Ask Your Question

Tracking a particular keyword from response in rabbitmq

asked 2015-09-07 02:23:26 -0500

itsme gravatar image

updated 2015-09-10 02:27:48 -0500

I have done the codes for fetching the response from queue.

My aim is to log all these in a file.

Whenever I am getting a particular response in a queue.

I need to log those things.

For example:

[x] '':'{"_context_roles": ["admin", "_member_", "heat_stack_owner"], "_context_request_id": "req-99bc87eb-3a97-4c05-9f67-1e2d683b8bf8", "_context_quota_class": null, "event_type": "compute.instance.create.end"

In this response We can see that there are some keywords were there.

Now what I need to do is logging a particular event.

In more clear way:

I need to track the response only for "event_type": "compute.instance.create.end" .

So that whenever I am getting a particular keyword in response I need to log the details in a file.

I have attached a code which I have done.

#!/usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(
channel =


result = channel.queue_declare(exclusive=True)
queue_name = ''

binding_keys = ''
if not binding_keys:
    print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)

for binding_key in binding_keys:

print ' [*] Waiting for logs. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] %r:%r" % (method.routing_key, body,)



I will be executing a file using the following method:

python > filename.log &

Now I am getting all reponse from particular queue using above code, Instead that I need to log only when I am getting particular keyword in reponse.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-09-28 05:06:32 -0500

Tosugueur gravatar image

Hi. Each time the callback is executed (a message is received) you need to verify weather the body contains the targeted sting - "event_type": "compute.instance.create.end" -. With a simple if statement you can exit the loop and display the result.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-09-07 02:23:26 -0500

Seen: 146 times

Last updated: Sep 28 '15