New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I connect event callback to tornado? #570

Closed
wyattsuen opened this Issue Aug 23, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@wyattsuen
Copy link

wyattsuen commented Aug 23, 2018

I have a service to accept data from remote servers, and need to broadcast the data to my other services. These other services(I use tornado) need to show these data on websocket connections. I think event driven program is suitable. But how can I use the @event_handler outside nameko but in tornado?

The document give the example, but I have no way to send the 'payload' to my tornado websocket server.

classs ServiceB:
     name='service_b'

    tornado_service=??   how can I inject the tornado websocket callback?

    @event_handler('service_a', 'event_type')
    def handle_event(self, payload):
        print('service b received:', payload)
        tornado_service.callback(payload)??       but tornado server can't embed in nameko server.

Are there any graceful way for nameko to open a standalone event handler in flask or tornado?

@mattbennett

This comment has been minimized.

Copy link
Contributor

mattbennett commented Aug 23, 2018

A Nameko event is just an AMQP message with a particular payload, so a standalone event handler is just something that consumes those messages. You should be able to use any AMQP library.

If I understand your question correctly, you could also use your Nameko service to communicate with your tornado services using a websocket connection. You can use the websocket-client library for that, and there's an example of using it in the nameko codebase.

@mattbennett

This comment has been minimized.

Copy link
Contributor

mattbennett commented Aug 23, 2018

For future reference, the forum is a better place for support questions like these. I will copy this issue there now and we can continue discussion on the forum if needs be.

@mattbennett mattbennett reopened this Aug 23, 2018

@mattbennett

This comment has been minimized.

Copy link
Contributor

mattbennett commented Aug 23, 2018

@wyattsuen

This comment has been minimized.

Copy link

wyattsuen commented Aug 25, 2018

Thanks very much for the reply and this very beatiful framework. I just use nameko in a week, and switch my most work architechture to it. I know I have to solve this problem with kombu. As I see the kombu document for these days, I find it difficult for me to understand the process without the rabbitmq experience. Can you help me to provide the example how to get event_handler outside nameko using kombu.

class ServiceA:
    """ Event dispatching service. """
    name = "service_a"

    dispatch = EventDispatcher()

    @rpc
    def dispatching_method(self, payload):
        self.dispatch("event_type", payload)

How to accept this event with SERVICE_POOL and BROADCAST method in kombu without nameko. I think the example will be very helpful to add to the nameko document. Or it is best to provide a standalone event_handler just like the standalone rpc service.

Although I have not met the problem, but I think it useful to send the event outside nameko, and accept the event in nameko is also welcome. Guessing tornado accept a message from user, and I want to send this message to many potential services, maybe broadcast the event is useful.

class ServiceB:
    """ Event listening service. """
    name = "service_b"

    @event_handler("service_a", "event_type")
    def handle_event(self, payload):
        print("service b received:", payload)

How to send the event with SERVICE_POOL and BROADCAST method in kombu without nameko. The examples are very important for us without rabbitmq experiences. So kindly and patiently providing the examples is welcome. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment