How to connect to the session outside of the ioloop?

#1

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?

0 Likes

#2

Outside of just writing a wrapper around publisher type ideally.

···

On Friday, April 21, 2017 at 3:57:12 PM UTC-5, ma...@x-qa.com wrote:

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?

0 Likes

#3

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

···

On Fri, Apr 21, 2017 at 5:01 PM ma...@x-qa.com wrote:

Outside of just writing a wrapper around publisher type ideally.

On Friday, April 21, 2017 at 3:57:12 PM UTC-5, ma...@x-qa.com wrote:

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?

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.

0 Likes

#4

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!

···

On Saturday, April 22, 2017 at 1:17:30 PM UTC-5, David Ford wrote:

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

On Fri, Apr 21, 2017 at 5:01 PM ma...@x-qa.com wrote:

Outside of just writing a wrapper around publisher type ideally.

On Friday, April 21, 2017 at 3:57:12 PM UTC-5, ma...@x-qa.com wrote:

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?

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 auto...@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.

0 Likes

#5

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

···

On Sat, Apr 22, 2017 at 9:04 PM ma...@x-qa.com wrote:

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!

On Saturday, April 22, 2017 at 1:17:30 PM UTC-5, David Ford wrote:

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

On Fri, Apr 21, 2017 at 5:01 PM ma...@x-qa.com wrote:

Outside of just writing a wrapper around publisher type ideally.

On Friday, April 21, 2017 at 3:57:12 PM UTC-5, ma...@x-qa.com wrote:

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?

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 autobah...@googlegroups.com.

To post to this group, send email to auto...@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.

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/b229bbc1-dc8d-49f8-8e97-4f5870956f11%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#6

Fair enough injust ended up passing a callback during instantiation

···

On Apr 25, 2017, 4:40 AM -0500, David Ford <firefig...@gmail.com>, wrote:

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
On Sat, Apr 22, 2017 at 9:04 PM <ma...@x-qa.com (mailto:ma...@x-qa.com)> wrote:
> 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!
>
>
>
> On Saturday, April 22, 2017 at 1:17:30 PM UTC-5, David Ford wrote:
> > 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
> > On Fri, Apr 21, 2017 at 5:01 PM <ma...@x-qa.com> wrote:
> > > Outside of just writing a wrapper around publisher type ideally.
> > >
> > >
> > > On Friday, April 21, 2017 at 3:57:12 PM UTC-5, ma...@x-qa.com wrote:
> > > > 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?
> > >
> > >
> > >
> > > --
> > > 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 autobah...@googlegroups.com.
> > > To post to this group, send email to auto...@googlegroups.com.
> > >
> > > To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/17c94e0a-258e-4db8-8b3c-41c5b32850f2%40googlegroups.com (https://groups.google.com/d/msgid/autobahnws/17c94e0a-258e-4db8-8b3c-41c5b32850f2%40googlegroups.com?utm_medium=email&utm_source=footer).
> > > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> 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 (mailto:autobahnws+...@googlegroups.com).
> To post to this group, send email to autob...@googlegroups.com (mailto:autob...@googlegroups.com).
> To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/b229bbc1-dc8d-49f8-8e97-4f5870956f11%40googlegroups.com (https://groups.google.com/d/msgid/autobahnws/b229bbc1-dc8d-49f8-8e97-4f5870956f11%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

--
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 (mailto:autobahnws+...@googlegroups.com).
To post to this group, send email to autob...@googlegroups.com (mailto:autob...@googlegroups.com).
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/CAFZ8Xq6imqZqe5ReTd4mq0ZvwGOjodCFV%3DSH%2B59OdnR%2BVmELBQ%40mail.gmail.com (https://groups.google.com/d/msgid/autobahnws/CAFZ8Xq6imqZqe5ReTd4mq0ZvwGOjodCFV%3DSH%2B59OdnR%2BVmELBQ%40mail.gmail.com?utm_medium=email&utm_source=footer).
For more options, visit https://groups.google.com/d/optout.

0 Likes