Some questions to clarify my mind and my understanding

#1

Hi,

if I want to get the new data from of a lot of RSS Feeds, do I have to do a RssComponent (for example) that publishes each new items and another EvernoteComponent that will subcribe to RssComponent to be able to get those new data ?

If so to be able to grab the new data periodically, do I have to do a while True: with a sleep() ?

As my Evenote service can also provide datas, can I use the same EvernoteComponent to declare a subscriber too ?

Or a component can not be a publisher AND a subscriber in the meantime ?

In others word can I have in the function onJoin(), 2 yields :

  • one with self.subscribe()
  • one with self.publish()

?

Once the data from the publisher are consummed, is there an “onFunction” I can use to know that the loop is over until the next time (after the sleep()) ?

Thank you for your help.

Regards

0 Likes

#2

Hi!

Having two components sounds reasonable.

Components can implement any number of WAMP roles - and being both a subscriber and a publisher is something that happens a lot in applications.

Regards,

Alex

···

Am Mittwoch, 18. Februar 2015 08:25:08 UTC+1 schrieb foxmask:

Hi,

if I want to get the new data from of a lot of RSS Feeds, do I have to do a RssComponent (for example) that publishes each new items and another EvernoteComponent that will subcribe to RssComponent to be able to get those new data ?

If so to be able to grab the new data periodically, do I have to do a while True: with a sleep() ?

As my Evenote service can also provide datas, can I use the same EvernoteComponent to declare a subscriber too ?

Or a component can not be a publisher AND a subscriber in the meantime ?

In others word can I have in the function onJoin(), 2 yields :

  • one with self.subscribe()
  • one with self.publish()

?

Once the data from the publisher are consummed, is there an “onFunction” I can use to know that the loop is over until the next time (after the sleep()) ?

Thank you for your help.

Regards

0 Likes

#3

OK thanks

0 Likes

#4

Hi,

one component can be a publisher and a subscriber at the same time. Actually, it can take any subset of the 4 WAMP roles (publisher, subscriber, caller, callee) at the same time.

Further, no, you don’t need to sleep somewhere unless you want to schedule your own code for some reasons. Autobahn will call your event handlers and procedures automatically as WAMP messages come in.

Cheers.
/Tobias

···

Am Mittwoch, 18. Februar 2015 08:25:08 UTC+1 schrieb foxmask:

Hi,

if I want to get the new data from of a lot of RSS Feeds, do I have to do a RssComponent (for example) that publishes each new items and another EvernoteComponent that will subcribe to RssComponent to be able to get those new data ?

If so to be able to grab the new data periodically, do I have to do a while True: with a sleep() ?

As my Evenote service can also provide datas, can I use the same EvernoteComponent to declare a subscriber too ?

Or a component can not be a publisher AND a subscriber in the meantime ?

In others word can I have in the function onJoin(), 2 yields :

  • one with self.subscribe()
  • one with self.publish()

?

Once the data from the publisher are consummed, is there an “onFunction” I can use to know that the loop is over until the next time (after the sleep()) ?

Thank you for your help.

Regards

0 Likes

#5

Hi,

Ok

But If I dont call yield sleep(xxx) i n the publisher, how to awake tihs one ?

Because currently, I have a component which is a subsriber and publisher, and that way (with the sleep in the publisher part) ; the subscriber part is never handled as it looks like the process is still in the While true + sleep() ; no ?

The code looks like this

class EvernoteComponent(ApplicationSession):

"""
    An application component that subscribes and receives events
"""

@inlineCallbacks
def onJoin(self, details):
    print("Evernote session attached")
    self.register(self)
   
    dbconfig = self.config.extra['database']

    self.db = txpostgres.Connection()
    try:
        yield self.db.connect(**dbconfig)
    except Exception as e:
        print("could not connect to database: {0}".format(e))
        self.leave()
        return
    else:
        print("PostgreSQL database adapter [subscriber role] connected to database")

    @inlineCallbacks
    def on_event(stuff):
        print('on event Evernote')
        # check with the trigger_id if the published data is related to Evernote
        trigger = yield self.call('eu.trigger-happy.evernote.trigger', stuff['trigger_id'])
        if (len(trigger)):
            # if the trigger is for Evernote, call "save"
            print("trigger id {0} pour evernote".format(stuff['trigger_id']))
            yield self.call('eu.trigger-happy.evernote.save_data', stuff, trigger)
        # else:
        #    print("trigger id {0} qui n'est pas pour evernote".format(stuff['trigger_id']))

    # Publishing
    while True:
        # get the trigger of the Evernote Service
        triggers = yield self.call(u'eu.trigger-happy.evernote.triggers')
        for data in triggers:
            # get the note
            # print(data)
            notes = yield self.call(u'eu.trigger-happy.evernote.process_data', data)
            # publish them
            yield self.publish(u'eu.trigger-happy.pushit',
                                {'trigger_id': data['trigger_id'],
                                 'user_id': data['user_id'],
                                 'item': notes})
        yield sleep(120)

    # Subscribing
    try:
        yield self.subscribe(on_event, u'eu.trigger-happy.pushit')
        print("Evernote subscribe topic")
    except Exception as e:
        print("Evernote could not subscribe to topic: {0}".format(e))

If I put the piece of while in comment ; then the subscribe part is handled.

···

Le dimanche 1 mars 2015 22:27:38 UTC+1, Tobias Oberstein a écrit :

Hi,

one component can be a publisher and a subscriber at the same time. Actually, it can take any subset of the 4 WAMP roles (publisher, subscriber, caller, callee) at the same time.

Further, no, you don’t need to sleep somewhere unless you want to schedule your own code for some reasons. Autobahn will call your event handlers and procedures automatically as WAMP messages come in.

Cheers.
/Tobias

Am Mittwoch, 18. Februar 2015 08:25:08 UTC+1 schrieb foxmask:

Hi,

if I want to get the new data from of a lot of RSS Feeds, do I have to do a RssComponent (for example) that publishes each new items and another EvernoteComponent that will subcribe to RssComponent to be able to get those new data ?

If so to be able to grab the new data periodically, do I have to do a while True: with a sleep() ?

As my Evenote service can also provide datas, can I use the same EvernoteComponent to declare a subscriber too ?

Or a component can not be a publisher AND a subscriber in the meantime ?

In others word can I have in the function onJoin(), 2 yields :

  • one with self.subscribe()
  • one with self.publish()

?

Once the data from the publisher are consummed, is there an “onFunction” I can use to know that the loop is over until the next time (after the sleep()) ?

Thank you for your help.

Regards

0 Likes

#6

But If I dont call yield sleep(xxx) i n the publisher, how to awake tihs
one ?

You don't need to wake up anything, as the event loop running inside the reactor will do that.

Because currently, I have a component which is a subsriber and
publisher, and that way (with the sleep in the publisher part) ; the
subscriber part is never handled as it looks like the process is still
in the While true + sleep() ; no ?

You have to make sure to use the right "sleep": in case of Twisted, autobahn.twisted.util.sleep() will do.

Python's sleep from stdlib will _not_ work (it will block the reactor).

/Tobias

0 Likes