Open altaurog opened 12 years ago
I've made a little progress on this. I'm realizing that callbacks work very differently under haigha than pika. The fact that callbacks operate in a synchronous manner is somewhat counter-intuitive, but I imagine that under gevent this doesn't affect performance. Perhaps I should re-evaluate using gevent.
In any case, the code below seems to work, but
How can I close the connection and exit cleanly after sending the message?
Is there a mailing list for discussing this project?
#!/usr/bin/env python
import logging
import sys
import event
from haigha.connection import Connection
from haigha.message import Message
class Client(object):
def __init__(self):
self.connection = Connection(transport='event')
self.channel = self.connection.channel()
self.channel.queue.declare(queue='hello',)
self.channel.basic.publish(Message('Hello World!'),
exchange='',
routing_key='hello',
)
def loop(self):
while not self.connection.close_info:
self.connection.read_frames()
def close(self):
print("closing")
self.connection.close()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
c = Client()
event.signal(2, sys.exit)
event.timeout(0, c.loop)
event.timeout(1, c.close)
event.dispatch()
There isn't a dedicated libevent example, but scripts/stress_test
uses libevent and you can pattern after that. You can pass a logger and debug handle into the Connection constructor and see similar trace output; I just added info to the DOCUMENTATION file regarding that.
You don't need to run your own read_frames loop for libevent, but also it needs to yield; the while True
part will block and essentially void your libevent benefits.
I like libevent, it was the first implementation of an async AMQP client that we had and the modern EventTransport-based haigha implementation is still in production in some of our applications. That said, I've fallen in love with the simplicity and power of gevent; it's our preferred transport these days and so is the one that receives the most testing.
The stress_test
script will give you a reasonable comparison between the two. I think libevent is still faster, but only by a bit, and the extra complexity may nullfiy the small gain in performance. I'm happy to help in your libevent pursuit as best I can. I recommend playing with the stress_test
script to get a feel for the options and performance characteristics.
There isn't a mailing list yet and github issues are a reasonable place to ask for assistance. It's tough to measure the uptake so I haven't considered a mailing list necessary.
I'm evaluating rabbitmq and python clients. This library looks much more mature than pika, but I need a little help figuring out how to use it. I am interested in asynchronous operation because I need an event loop in which I can schedule various tasks, however I prefer event over gevent; we haven't been using gevent and it seems to add more complexity than I want at the moment. I guess my other option is to use the 'socket' transport and implement my own loop in which I call connection.read_frames().
Here's my attempt at a publisher:
Here's what I see when I run the code:
Using the tracer supplied with the rabbit java client, I see the following:
How do I make it work?