<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>kazoo module uses whatever rabbitmq supports (<span style="color:rgb(85,85,85); font-family:Verdana,sans-serif; font-size:13px; background-color:rgb(247,247,247)">AMQP 0-9-1)</span></p>
<p><a href="https://www.rabbitmq.com/protocol.html" class="x_OWAAutoLink" id="LPlnk777552">https://www.rabbitmq.com/protocol.html</a></p>
<p><br>
</p>
<p>content type is</p>
<p></p>
<div><span class="x_Apple-tab-span" style="white-space:pre"></span>props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG;</div>
<div><span class="x_Apple-tab-span" style="white-space:pre"></span>props.content_type = amqp_cstring_bytes("application/json");</div>
<div><br>
</div>
<div>this is enforced in publishing and consuming</div>
<div><br>
</div>
<div>and the proper url for the kazoo module would be <a href="https://github.com/kamailio/kamailio/tree/master/src/modules/kazoo" class="x_OWAAutoLink" id="LPlnk744284">https://github.com/kamailio/kamailio/tree/master/src/modules/kazoo</a></div>
<br>
<div>kazoo module is built with <a href="https://github.com/alanxz/rabbitmq-c" class="x_OWAAutoLink" id="LPlnk907802">
https://github.com/alanxz/rabbitmq-c</a></div>
<br>
<p></p>
<p>if you're using python, you may want to try <a href="https://pika.readthedocs.io/en/0.10.0/" class="x_OWAAutoLink" id="LPlnk824946">https://pika.readthedocs.io/en/0.10.0/</a> instead</p>
<br>
hope this helps
<div><br>
</div>
<div>Cheers</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Daniel Pocock <daniel@pocock.pro><br>
<b>Sent:</b> Monday, April 3, 2017 10:18:39 AM<br>
<b>To:</b> users@qpid.apache.org<br>
<b>Cc:</b> Engineering; Luis Azedo; sr-dev@lists.sip-router.org<br>
<b>Subject:</b> Re: qpid-proton and rabbitmq (and Kamailio kazoo module)</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
<br>
On 30/03/17 13:25, Gordon Sim wrote:<br>
> On 30/03/17 09:52, Daniel Pocock wrote:<br>
>> Sending to RabbitMQ with qpid-proton python<br>
>> -------------------------------------------<br>
>><br>
>> I started with the simple_send.py[3] example and trimmed it down to send<br>
>> a single string and then stop:<br>
>><br>
>>     def on_sendable(self, event):<br>
>>         if self.msg_body is not None:<br>
>>             print("on_sendable !")<br>
>>             print ("sending : %s" % (self.msg_body,))<br>
>>             msg = Message(body=self.msg_body)<br>
>>             event.sender.send(msg)<br>
>>             self.msg_body = None<br>
>><br>
>> I found that the connection to RabbitMQ would be dropped and an error<br>
>> would appear in the RabbitMQ log.  I tried changing the body type to a<br>
>> dict containing a string, e.g. {'my_body':'foo'} and then it would<br>
>> successfully pass the message to RabbitMQ but then the receiver would<br>
>> complain that it was a map and not a string.<br>
>><br>
>> I found that the problem could be fixed by adding "inferred=True" to the<br>
>> Message constructor:<br>
>><br>
>>             msg = Message(body=self.msg_body, inferred=True)<br>
> <br>
> <br>
> The python proton library will encode a binary message body as a Data<br>
> section if inferred is not set to true (otherwise as a binary value in a<br>
> Value section). RabbitMQ does not support Data sections yet I believe.<br>
> <br>
<br>
<br>
Is there a bug or feature request for Data sections in RabbitMQ?  I<br>
couldn't find their bug tracker.  I've opened a bug report[1] against<br>
the Debian package.<br>
<br>
<br>
> As Robbie mentioned, in python 2.x string literals are not always<br>
> explicitly utf8 and are then treated as binary. You can either do u'my<br>
> utf8' or import unicode_literals from __future__. If you do that then<br>
> you should get a Value section regardless of the inferred property.<br>
> <br>
<br>
In my case the strings are coming from the command line, so now I change<br>
the string to unicode like this:<br>
<br>
   _s = unicode(s, "utf-8")<br>
<br>
and then:<br>
<br>
a) I can send without inferred=True and the broker accepts the message<br>
<br>
b) in the C++ receiver, the message is now received as a string and I<br>
can use:<br>
<br>
    _json = proton::get<std::string>(m.body());<br>
<br>
<br>
Could this be made more obvious in the examples perhaps, e.g.<br>
helloworld.py could change from:<br>
<br>
    event.sender.send(Message(body="Hello World!"))<br>
<br>
to<br>
<br>
    event.sender.send(Message(body=unicode("Hello World!", "utf-8")))<br>
<br>
I realize that is a bit verbose and redundant when you already have<br>
unicode_literals, but for people who are cutting and pasting from the<br>
examples they will get up and running more quickly.<br>
<br>
<br>
>> Below is a complete example of the error from the RabbitMQ log when<br>
>> inferred=True is not present, the body in this case was the string "foo"<br>
>><br>
>><br>
>> Receiving from RabbitMQ with qpid-proton C++<br>
>> --------------------------------------------<br>
>><br>
>> I looked at the receive example simple_recv.cpp[4] and other examples<br>
>> and noticed code like this being used to access the message body as<br>
>> std::string:<br>
>><br>
>> proton::get<std::string>(m.body())<br>
>><br>
>> However, that didn't work for me, it threw a conversion_error exception<br>
>> "unexpected type, want: string got: binary" complaining that the body<br>
>> was binary.  I had to use something like this to convert my message body<br>
>> to a std::string:<br>
>><br>
>>    proton::binary __b = proton::get<proton::binary>(m.body());<br>
>>    std::string _s = (std::string)__b;<br>
>><br>
>> If I send a string from Python, should it appear as binary in the<br>
>> receiver?<br>
> <br>
> As above it sounds like the message *is* actually being sent as a binary.<br>
> <br>
>> What is the suggested way to write a receiver that can handle<br>
>> any arbitrary message that started as a string and may arrive in some<br>
>> other format, especially if the message broker or client is changed at<br>
>> some arbitrary time in the future?<br>
>><br>
>> I also observed similar issues receiving messages that had been sent<br>
>> into RabbitMQ by Kamailio's kazoo module[5], it is linked with the<br>
>> librabbitmq client library.<br>
> <br>
> I'm assuming that is sending over AMQP 0-10. If so, how that is<br>
> converted into AMQP 1.0 is dependent on the RabbitMQ implementation. It<br>
> may well be always sent as a binary value. However hopefully it would<br>
> have a content-type to indicate how to interpret the data (though<br>
> structly speaking the AMQP 1.0 spec disallows that).<br>
> <br>
<br>
<br>
The kazoo module source code is on Github[2], I had a quick look at it<br>
and it isn't immediately obvious to me which AMQP version it uses or<br>
which data type it is using for the message body.  Is anybody more<br>
familiar with AMQP C client programming able to spot any keywords in<br>
that code that suggest what it is doing?  I've added the kazoo module<br>
developers on CC in case they can comment on this, it would be useful to<br>
answer this in the module's README file.<br>
<br>
Regards,<br>
<br>
Daniel<br>
<br>
1. <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=859399">http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=859399</a><br>
2. <a href="https://github.com/sipwise/kamailio/tree/master/modules/kazoo">https://github.com/sipwise/kamailio/tree/master/modules/kazoo</a><br>
</div>
</span></font>
</body>
</html>