You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by serega <se...@sap.com> on 2014/03/26 21:56:52 UTC

Quotes in the message body

I am using Qpid Proton Messenger with SwiftMQ JMS/AMQP broker.  On the
receiving side the messenger surrounds message body with quotes.
smeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>./send
-a  amqp://10.250.0.127:5672/testqueue
Message_without_quotessmeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>smeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>./recv 
amqp://10.250.0.127:5672/testqueueAddress:
amqp://10.250.0.127:5672/testqueueSubject: (no subject)Content:
"Message_without_quotes"
Notice the '"' character on both sides of the body. The SwiftMQ is JMS
broker which gives me more options to test. Receiving this message using JMS
API yields a message body without quotes, so it clearly happens on the
quid-proton receiving side.   I am stripping out the quotes, but I prefer to
receive the original message without quotes.   - Sergey



--
View this message in context: http://qpid.2158936.n2.nabble.com/Quotes-in-the-message-body-tp7606053.html
Sent from the Apache Qpid Proton mailing list archive at Nabble.com.

Re: Quotes in the message body

Posted by Fraser Adams <fr...@blueyonder.co.uk>.
On 28/03/14 15:20, serega wrote:
> Thanks for the explanation. Yes, I used recv client.
>
> I had to also call pn_data_next(body) to make it work, so it looks like so
> --------------------------------------------------------------------------
> pn_data_t *body = pn_message_body(message);
> pn_data_next(body);
> pn_bytes_t bytes =  pn_data_get_string(body);
> --------------------------------------------------------------------------
Ahh sorry I missed the  pn_data_next stuff. TBH I'm as much of a novice 
to this API as you :-/

Funnily enough I'm working my way through it by looking at the python 
binding in <proton>/proton-c/bindings/python/proton.py I know it might 
sound a bit obtuse, but python has a fairly natural OO API and uses 
introspection, so if you are looking for how to encode and decode things 
looking at the python stuff shows most of what you need, unfortunately I 
missed a "cheeky post decode" call when I first replied ......

   def _post_decode(self):
     inst = Data(pn_message_instructions(self._msg))
     ann = Data(pn_message_annotations(self._msg))
     props = Data(pn_message_properties(self._msg))
     body = Data(pn_message_body(self._msg))

     if inst.next():
       self.instructions = inst.get_object()
     else:
       self.instructions = None
     if ann.next():
       self.annotations = ann.get_object()
     else:
       self.annotations = None
     if props.next():
       self.properties = props.get_object()
     else:
       self.properties = None
     if body.next():
       self.body = body.get_object()
     else:
       self.body = None


I can see now that there's a call to pn_data_next (wrapped by the 
body.next() call).

By the way judging from this, for safety it looks like you should also 
be checking the return value of pn_data_next and only calling your 
pn_data_get_string if the return value is true.

>
> The Qpid Proton needs more documentation and/or example code. The
> messenger.h is very well documented, but I couldn't find any documentation
> on how to read and write data (properties, body) from and to a message.
I agree, I actually posted on a related topic on the qpid users mailing 
list - the good news is that improved API documentation should be 
happening fairly soon.

Regards,
Frase


Re: Quotes in the message body

Posted by serega <se...@sap.com>.
Thanks for the explanation. Yes, I used recv client. 

I had to also call pn_data_next(body) to make it work, so it looks like so 
--------------------------------------------------------------------------
pn_data_t *body = pn_message_body(message);
pn_data_next(body);
pn_bytes_t bytes =  pn_data_get_string(body);
--------------------------------------------------------------------------

The Qpid Proton needs more documentation and/or example code. The
messenger.h is very well documented, but I couldn't find any documentation
on how to read and write data (properties, body) from and to a message.  

Sergey



--
View this message in context: http://qpid.2158936.n2.nabble.com/Quotes-in-the-message-body-tp7606053p7606167.html
Sent from the Apache Qpid Proton mailing list archive at Nabble.com.

Re: Quotes in the message body

Posted by Fraser Adams <fr...@blueyonder.co.uk>.
Hello,
If you are using the recv client (which you look like you are using) 
then I *think* that what you are seeing is an artefact of that using 
pn_data_format, which generates a *formatted* response. I think that's 
because recv is intended to be a fairly general test client - when I 
sent a UUID to it the other day it displayed something like 
UUID(<my-uuid>), so the quotes are an artefact of the rendering rather 
than anything transmitted over the wire.

What you'd need to do is to have a client that did pn_data_get_string 
rather than pn_data_format. One thing to bear in mind is that 
pn_data_get_string returns a pn_bytes_t structure and not a char* string 
it looks something like:

typedef struct {
   size_t size;
   char *start;
} pn_bytes_t;

The call you'd need to make would I think look like:

pn_bytes_t bytes = pn_data_get_string(body);

But you'd need to make sure that you then created your own char* style 
null terminated string using the start and size stuff from bytes (likely 
via malloc and memcpy).

So in short I think that it relates to the recv client and if you want 
the unformatted string then you'd need to modify that to retrieve the 
string directly.

I'm still finding my own feet with the messenger API if there's a better 
approach then hopefully someone more authoritative will chip in.

HTH,
Frase


On 26/03/14 20:56, serega wrote:
> I am using Qpid Proton Messenger with SwiftMQ JMS/AMQP broker.  On the
> receiving side the messenger surrounds message body with quotes.
> smeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>./send
> -a  amqp://10.250.0.127:5672/testqueue
> Message_without_quotessmeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>smeldris@labitpf2:~/qpid-proton-0.6/build/proton-c/examples/messenger/c>./recv
> amqp://10.250.0.127:5672/testqueueAddress:
> amqp://10.250.0.127:5672/testqueueSubject: (no subject)Content:
> "Message_without_quotes"
> Notice the '"' character on both sides of the body. The SwiftMQ is JMS
> broker which gives me more options to test. Receiving this message using JMS
> API yields a message body without quotes, so it clearly happens on the
> quid-proton receiving side.   I am stripping out the quotes, but I prefer to
> receive the original message without quotes.   - Sergey
>
>
>
> --
> View this message in context: http://qpid.2158936.n2.nabble.com/Quotes-in-the-message-body-tp7606053.html
> Sent from the Apache Qpid Proton mailing list archive at Nabble.com.