Sending object to Nameko from logstash via rabbitmq

Godd evening to everyone,

I've a nameko method annotated like this:

@event_handler("logstash_in", "new_item")

def new_item_event(self, item_type, item_body):

    do_stuff_with(item_body)

And I would like to send a message to the nameko service from logstash.

The source json is something like this:
{
   "type":"vod",

   "field":"text",
   "field1": False
}

What I would like to do is to send a message that will be received this way
by the nameko service:

item_type = "vod"

item_body = {
   "type":"vod",

   "field":"text",
   "field1": False
}

Thank you in advance,

Simone

You probably want to be using the @consume entrypoint and Publisher (in
nameko.messaging), rather than events.

Events are specifically about subscribing to something that happened in
another service:

@event_handler("<source-service-name>", "<event-type>")
def handle(self, event_data):
    # handles <event-type> events from <source-service>

In your example, I guess you don't have another service called
"logstash_in".

In contrast, publish/consume is about generic AMQP messaging, which is more
flexible.

You probably want something that looks like this:

from kombu.messaging import Queue, Exchange
from nameko.messaging import Publisher, consume

logstash_exchange = Exchange("logstash")
vod_queue = Queue(name="logstash", exchange=logstash_exchange,
routing_key="vod")

class ConsumerService(object):
    name = "consumer"

    @consume(vod_queue)
    def consume(self, payload):
        # ...
        pass

class PublisherService(object):
    name = "publisher"

    publish = Publisher(exchange=logstash_exchange)

    def send_to_logstash(self):
        # send "vod" type payload; will be routed to the "vod_queue"
        self.publish(routing_key="vod", {...})

···

On Saturday, March 11, 2017 at 2:26:56 AM UTC, Simone Pontiggia wrote:

Godd evening to everyone,

I've a nameko method annotated like this:

@event_handler("logstash_in", "new_item")

def new_item_event(self, item_type, item_body):

    do_stuff_with(item_body)

And I would like to send a message to the nameko service from logstash.

The source json is something like this:
{
   "type":"vod",

   "field":"text",
   "field1": False
}

What I would like to do is to send a message that will be received this
way by the nameko service:

item_type = "vod"

item_body = {
   "type":"vod",

   "field":"text",
   "field1": False
}

Thank you in advance,

Simone