qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Sim <g...@redhat.com>
Subject Re: qpid-proton and rabbitmq
Date Thu, 30 Mar 2017 11:25:16 GMT
On 30/03/17 09:52, Daniel Pocock wrote:
> Sending to RabbitMQ with qpid-proton python
> -------------------------------------------
> I started with the simple_send.py[3] example and trimmed it down to send
> a single string and then stop:
>     def on_sendable(self, event):
>         if self.msg_body is not None:
>             print("on_sendable !")
>             print ("sending : %s" % (self.msg_body,))
>             msg = Message(body=self.msg_body)
>             event.sender.send(msg)
>             self.msg_body = None
> I found that the connection to RabbitMQ would be dropped and an error
> would appear in the RabbitMQ log.  I tried changing the body type to a
> dict containing a string, e.g. {'my_body':'foo'} and then it would
> successfully pass the message to RabbitMQ but then the receiver would
> complain that it was a map and not a string.
> I found that the problem could be fixed by adding "inferred=True" to the
> Message constructor:
>             msg = Message(body=self.msg_body, inferred=True)

The python proton library will encode a binary message body as a Data 
section if inferred is not set to true (otherwise as a binary value in a 
Value section). RabbitMQ does not support Data sections yet I believe.

As Robbie mentioned, in python 2.x string literals are not always 
explicitly utf8 and are then treated as binary. You can either do u'my 
utf8' or import unicode_literals from __future__. If you do that then 
you should get a Value section regardless of the inferred property.

> Below is a complete example of the error from the RabbitMQ log when
> inferred=True is not present, the body in this case was the string "foo"
> Receiving from RabbitMQ with qpid-proton C++
> --------------------------------------------
> I looked at the receive example simple_recv.cpp[4] and other examples
> and noticed code like this being used to access the message body as
> std::string:
> proton::get<std::string>(m.body())
> However, that didn't work for me, it threw a conversion_error exception
> "unexpected type, want: string got: binary" complaining that the body
> was binary.  I had to use something like this to convert my message body
> to a std::string:
>    proton::binary __b = proton::get<proton::binary>(m.body());
>    std::string _s = (std::string)__b;
> If I send a string from Python, should it appear as binary in the
> receiver?

As above it sounds like the message *is* actually being sent as a binary.

> What is the suggested way to write a receiver that can handle
> any arbitrary message that started as a string and may arrive in some
> other format, especially if the message broker or client is changed at
> some arbitrary time in the future?
> I also observed similar issues receiving messages that had been sent
> into RabbitMQ by Kamailio's kazoo module[5], it is linked with the
> librabbitmq client library.

I'm assuming that is sending over AMQP 0-10. If so, how that is 
converted into AMQP 1.0 is dependent on the RabbitMQ implementation. It 
may well be always sent as a binary value. However hopefully it would 
have a content-type to indicate how to interpret the data (though 
structly speaking the AMQP 1.0 spec disallows that).

To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org

View raw message