[rabbitmq-discuss] Alternative Python AMQP client library

15 views
Skip to first unread message

Barry Pederson

unread,
Dec 3, 2007, 4:50:35 PM12/3/07
to rabbitmq...@lists.rabbitmq.com
I've seen a few Python users on this list, so I thought I'd mention that
I've been working on a Python AMQP client library as an alternative to
Qpid, and have a Mercurial repository and initial tarball available at:

http://barryp.org/software/py-amqplib/

The library is a bit rough, but I've been using it with RabbitMQ for a
while now.

It differs from Qpid in that it doesn't require a spec file (although
one was used to generate the initial skeleton), and it doesn't rely on
threading (making it a bit easier to debug and use with a Python
interpreter embedded in another app).

Barry

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq...@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

Dmitriy Samovskiy

unread,
Dec 4, 2007, 1:29:43 PM12/4/07
to Barry Pederson, rabbitmq...@lists.rabbitmq.com
Hi Barry,

Barry Pederson wrote:
> I've seen a few Python users on this list, so I thought I'd mention that
> I've been working on a Python AMQP client library as an alternative to
> Qpid, and have a Mercurial repository and initial tarball available at:
>
> http://barryp.org/software/py-amqplib/
>
> The library is a bit rough, but I've been using it with RabbitMQ for a
> while now.

Great stuff, and thanks for releasing it under a public license!

Is there a way to get a non-blocking consumer event loop using your library?

Thanks,
Dmitriy

Brian Granger

unread,
Dec 4, 2007, 2:15:02 PM12/4/07
to Dmitriy Samovskiy, rabbitmq...@lists.rabbitmq.com
>
> Barry Pederson wrote:
> > I've seen a few Python users on this list, so I thought I'd mention that
> > I've been working on a Python AMQP client library as an alternative to
> > Qpid, and have a Mercurial repository and initial tarball available at:
> >
> > http://barryp.org/software/py-amqplib/
> >
> > The library is a bit rough, but I've been using it with RabbitMQ for a
> > while now.
>
> Great stuff, and thanks for releasing it under a public license!
>
> Is there a way to get a non-blocking consumer event loop using your library?

Twisted would be the way to go for this.

Brian

Barry Pederson

unread,
Dec 4, 2007, 3:48:48 PM12/4/07
to Dmitriy Samovskiy, rabbitmq...@lists.rabbitmq.com
Dmitriy Samovskiy wrote:

> Is there a way to get a non-blocking consumer event loop using your
> library?

Channel.basic_get() doesn't block, it just returns None if the queue is
empty. So you could poll that occasionally in your own loop - but the
downside would be more network traffic back and forth.

Barry

Tony Garnock-Jones

unread,
Dec 27, 2007, 9:25:16 AM12/27/07
to Barry Pederson, rabbitmq...@lists.rabbitmq.com
Hi Barry,

Barry Pederson wrote:
> http://barryp.org/software/py-amqplib/
> The library is a bit rough, but I've been using it with RabbitMQ for a
> while now.

It looks great. The code is straightforward and easy-to-read. I like the
way the docstrings have been built from the specification and included
directly in the source.

I see there's SSL support in there. How have you been experimenting with
this? Using stunnel to proxy the rabbitmq server?

Regards,
Tony
--
[][][] Tony Garnock-Jones | Mob: +44 (0)7905 974 211
[][] LShift Ltd | Tel: +44 (0)20 7729 7060
[] [] http://www.lshift.net/ | Email: to...@lshift.net

Barry Pederson

unread,
Dec 27, 2007, 9:56:09 AM12/27/07
to Tony Garnock-Jones, rabbitmq...@lists.rabbitmq.com
Tony Garnock-Jones wrote:
> Hi Barry,
>
> Barry Pederson wrote:
>> http://barryp.org/software/py-amqplib/
>> The library is a bit rough, but I've been using it with RabbitMQ for a
>> while now.
>
> It looks great. The code is straightforward and easy-to-read. I like the
> way the docstrings have been built from the specification and included
> directly in the source.
>
> I see there's SSL support in there. How have you been experimenting with
> this? Using stunnel to proxy the rabbitmq server?

Thanks.

Yes, I've been using stunnel 4.21, I think the only thing I had to tweak
in the stunnel.conf was to set

sslVersion = all

instead of the default (at least default on the FreeBSD stunnel port)

sslVersion = SSLv3

since it seemed that the Python 2.5 SSL support was for SSLv2 only.

Barry

kyles

unread,
Jan 30, 2008, 4:40:14 PM1/30/08
to rabbitmq...@lists.rabbitmq.com

Hi Barry,


Barry Pederson wrote:
>
> I've seen a few Python users on this list, so I thought I'd mention that
> I've been working on a Python AMQP client library as an alternative to
> Qpid, and have a Mercurial repository and initial tarball available at:
>
> http://barryp.org/software/py-amqplib/
>
> The library is a bit rough, but I've been using it with RabbitMQ for a
> while now.
>

I've been unable to get the amqplib client working when I'm running 2 or
more nodes in a RabbitMQ cluster. Using a single node (local or remote)
works fine. The error I'm getting is:

Traceback (most recent call last):
File "demo_send.py", line 56, in <module>
main()
File "demo_send.py", line 41, in main
conn = amqp.Connection(options.host, userid=options.userid,
password=options.password, ssl=options.ssl)
File "/usr/local/lib/python2.5/site-packages/amqplib/client_0_8.py", line
180, in __init__
self.close()
File "/usr/local/lib/python2.5/site-packages/amqplib/client_0_8.py", line
420, in close
(10, 61), # Connection.close_ok
File "/usr/local/lib/python2.5/site-packages/amqplib/client_0_8.py", line
356, in wait
frame_type, payload = self._wait_channel(0)
File "/usr/local/lib/python2.5/site-packages/amqplib/client_0_8.py", line
298, in _wait_channel
frame_type, frame_channel, payload = self._wait_frame()
File "/usr/local/lib/python2.5/site-packages/amqplib/client_0_8.py", line
273, in _wait_frame
frame_type = self.input.read_octet()
File "/usr/local/lib/python2.5/site-packages/amqplib/util_0_8.py", line
96, in read_octet
return unpack('B', self.input.read(1))[0]
File "/usr/local/lib/python2.5/struct.py", line 87, in unpack
return o.unpack(s)
struct.error: unpack requires a string argument of length 1
Exception socket.error: (32, 'Broken pipe') in <bound method
Connection.__del__ of <amqplib.client_0_8.Connection object at 0xb7c7470c>>
ignored

Is this something you've seen before?

Thanks,
Kyle
--
View this message in context: http://www.nabble.com/Alternative-Python-AMQP-client-library-tp14139740p15192757.html
Sent from the RabbitMQ mailing list archive at Nabble.com.

Barry Pederson

unread,
Jan 30, 2008, 7:37:47 PM1/30/08
to kyles, rabbitmq...@lists.rabbitmq.com

Sorry, I haven't had a multi-node RabbitMQ setup to try anything like
that particular setup, so haven't seen that particular error.

It looks like the node you're connecting to is maybe trying to redirect
you to the other node, and then closing the socket without waiting for
the client to send a "close" message and then responding with "close-ok".

(Does the server initiate the exchange of "close"/"close-ok" messages
after a redirect? It wasn't clear to me from the specs.)

Anyhow, an easy workaround would be to wrap the call to self.close() in
line 180 of amqplib/client_0_8.py in a try/except block - so try
changing this:

--------
# we were redirected, close the socket, loop and try again
self.close()
--------

to this:

---------
# we were redirected, close the socket, loop and try again
try:
self.close()
except:
pass
---------

that might do the trick.

Barry

Dmitriy Samovskiy

unread,
Feb 1, 2008, 6:39:03 PM2/1/08
to Barry Pederson, rabbitmq...@lists.rabbitmq.com, kyles

Barry Pederson wrote:

Yes, I get the same very exception when broker replies with a redirect.

You can also use insist flag when starting a connection:

client = Connection(host=myip, userid='guest', password='guest', insist=True)

This should work with the latest version of amqplib.

In my tests I have never seen a broker respond with redirect when I set insist to True,
even though according to the spec, a broker SHOULD accept a connection (not MUST):

<field name="insist" type="bit">
insist on connecting to server
<doc>
In a configuration with multiple load-sharing servers, the server
may respond to a Connection.Open method with a Connection.Redirect.
The insist option tells the server that the client is insisting on
a connection to the specified server.
</doc>
<rule implement="SHOULD">
When the client uses the insist option, the server SHOULD accept
the client connection unless it is technically unable to do so.
</rule>
</field>


- Dmitriy

Reply all
Reply to author
Forward
0 new messages