How to connect to the session outside of the ioloop?

31 views
Skip to first unread message

ma...@x-qa.com

unread,
Apr 21, 2017, 4:57:12 PM4/21/17
to Autobahn
I am trying to setup a pub/sub framework with crossbar but lacking how to publish events from outside of the loop.

producer.py:
"""
Producer Module
"""
import json

from twisted.internet.defer import inlineCallbacks

from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
from autobahn.wamp.types import PublishOptions

from eventify import Eventify


class ProducerApp(ApplicationSession):
    """
    Handle methods for publishing methods to
    transport
    """

    @inlineCallbacks
    def onJoin(self, details):
        print("session joined")
        topic = self.config.extra['publish_topic']['topic']
        pub_options = PublishOptions(**self.config.extra['pub_options'])
        message = json.dumps({
            "event": "UiEventProducerStarted"
        })

        # Publish Service Started
        yield self.publish(
            topic,
            message,
            options=pub_options
        )

class Producer(Eventify):

    def start(self):
        """
Run application
"""

        # Configure application
        runner = ApplicationRunner(
   url=self.config['transport_host'],
   realm=u"realm1",
   extra=self.config
        )

        # Start event loop
        runner.run(
            ProducerApp,
            auto_reconnect=True
        )


My application:

from eventify.producer import Producer


if __name__ == '__main__':
    """
    Start the producer service
    """
    print('Starting UI event message producer...')
    producer = Producer(config_file='config.json')
    producer.start()


What I would like to do:

from eventify.producer import Producer


if __name__ == '__main__':
    """
    Start the producer service
    """
    print('Starting UI event message producer...')
    producer = Producer(config_file='config.json')
    producer.start()

    # Send event to crossbar
    producer.publish("some event happened")


Goal to reduce boilerplate to only focus on writing business logic.

Thoughts? or links to relevant docs?

ma...@x-qa.com

unread,
Apr 21, 2017, 5:01:34 PM4/21/17
to Autobahn
Outside of just writing a wrapper around publisher type ideally.

David Ford

unread,
Apr 22, 2017, 2:17:30 PM4/22/17
to Autobahn
look at provider.py in https://github.com/Blue-Labs/misty

the wamp portion runs in its own thread and the calendar app is split, sends/receives as its own unit using queues

--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/17c94e0a-258e-4db8-8b3c-41c5b32850f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ma...@x-qa.com

unread,
Apr 22, 2017, 9:04:00 PM4/22/17
to Autobahn
Thanks reviewing! 1800 lines in one file though; perhaps break it up some? ... goes of on random project and creates pull request to make a bit more maintainable for myself. j/k. Will look after I write something to find all the residents of my city and alert them to my missing cat... Always jumping to random projects.

Thanks!

David Ford

unread,
Apr 25, 2017, 5:40:58 AM4/25/17
to Autobahn
np. heheh, that's on my #todo. been keeping it as a single file for the moment as i dist it around to all my raspberry pi nodes

Matthew Harris

unread,
Apr 25, 2017, 8:42:39 AM4/25/17
to Autobahn
Fair enough injust ended up passing a callback during instantiation

You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/4tgOgzHCWBM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.

To post to this group, send email to autob...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages