publish and consume working
This commit is contained in:
parent
5c3f12f761
commit
c2ac9b8bf8
32
bin/event_consumer.py
Normal file
32
bin/event_consumer.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""The consumer part of event_pump. Uses Notabene to read
|
||||
published notifications.
|
||||
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from notabene import kombu_driver as driver
|
||||
|
||||
|
||||
class Callback(object):
|
||||
x = 0
|
||||
def on_event(self, deployment, routing_key, body, exchange):
|
||||
print "Got:", body
|
||||
self.x += 1
|
||||
if self.x > 10:
|
||||
sys.exit(1)
|
||||
|
||||
def shutting_down(self):
|
||||
print "Shutting down"
|
||||
|
||||
config = {"topics":{
|
||||
"monitor":[
|
||||
{"queue":"monitor.info",
|
||||
"routing_key":"monitor.info"},
|
||||
]
|
||||
}}
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
driver.start_worker(Callback(), "event_consumer", 1, config,
|
||||
"monitor", logging)
|
||||
|
@ -18,10 +18,11 @@ connection = driver.create_connection("localhost", 5672, 'guest', 'guest',
|
||||
"librabbitmq", "/")
|
||||
exchange = driver.create_exchange("monitor", "topic")
|
||||
queue_name = "monitor.info"
|
||||
queue = driver.create_queue(queue_name, exchange, queue_name, channel=connection.channel())
|
||||
queue = driver.create_queue(queue_name, exchange, queue_name,
|
||||
channel=connection.channel())
|
||||
queue.declare()
|
||||
|
||||
g = notigen.EventGenerator(100) # Number of operations per minute
|
||||
g = notigen.EventGenerator(1000) # Number of operations per minute
|
||||
now = datetime.datetime.utcnow()
|
||||
start = now
|
||||
nevents = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user