# Sending object to Nameko from logstash via rabbitmq

**URL:** <https://discourse.nameko.io/t/sending-object-to-nameko-from-logstash-via-rabbitmq/172>\
**Category:** googlegroup\
**Created:** [March 11, 2017, 2:26am UTC](https://discourse.nameko.io/t/sending-object-to-nameko-from-logstash-via-rabbitmq/172 "2017-03-11T02:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simone\_Pontiggia](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@Simone\_Pontiggia](https://discourse.nameko.io/u/Simone_Pontiggia)\
**Post date:** [March 11, 2017, 2:26am UTC](https://discourse.nameko.io/t/sending-object-to-nameko-from-logstash-via-rabbitmq/172/1 "2017-03-11T02:26:55Z")

</div>

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):

&nbsp;&nbsp;&nbsp;&nbsp;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:  
{  
&nbsp;&nbsp;&nbsp;"type":"vod",

&nbsp;&nbsp;&nbsp;"field":"text",  
&nbsp;&nbsp;&nbsp;"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 = {  
&nbsp;&nbsp;&nbsp;"type":"vod",

&nbsp;&nbsp;&nbsp;"field":"text",  
&nbsp;&nbsp;&nbsp;"field1": False  
}

Thank you in advance,

Simone

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [March 11, 2017, 11:13am UTC](https://discourse.nameko.io/t/sending-object-to-nameko-from-logstash-via-rabbitmq/172/2 "2017-03-11T11:13:55Z")

</div>

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):  
&nbsp;&nbsp;&nbsp;&nbsp;# 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):  
&nbsp;&nbsp;&nbsp;&nbsp;name = "consumer"

&nbsp;&nbsp;&nbsp;&nbsp;@consume(vod\_queue)  
&nbsp;&nbsp;&nbsp;&nbsp;def consume(self, payload):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass

class PublisherService(object):  
&nbsp;&nbsp;&nbsp;&nbsp;name = "publisher"

&nbsp;&nbsp;&nbsp;&nbsp;publish = Publisher(exchange=logstash\_exchange)

&nbsp;&nbsp;&nbsp;&nbsp;def send\_to\_logstash(self):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# send "vod" type payload; will be routed to the "vod\_queue"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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):
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;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:  
> > {  
> > &nbsp;&nbsp;&nbsp;"type":"vod",
> > 
> > &nbsp;&nbsp;&nbsp;"field":"text",  
> > &nbsp;&nbsp;&nbsp;"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 = {  
> > &nbsp;&nbsp;&nbsp;"type":"vod",
> > 
> > &nbsp;&nbsp;&nbsp;"field":"text",  
> > &nbsp;&nbsp;&nbsp;"field1": False  
> > }
> > 
> > Thank you in advance,
> > 
> > Simone
