You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by Arun Dsouza <ar...@microsoft.com> on 2013/03/22 20:01:14 UTC

Getting AMQP message properties though Proton-C

I would like to know the correct way to access AMQP message properties through Proton-C. If this the not the right mailing list  for Proton-C usage queries, I apologize and please direct me to the mailing list.

The scenario I have is an interop scenario where I send messages to a  Windows Azure Service Bus queue using  the Service Bus .NET API,  and I receive from the queue using the Linux version of the Proton-C client ( Release 0.4 )
While sending messages I set some properties on AMQP message, and I want to get those properties from the Proton-C receiver. The properties are simple key value pairs where the Key is a string and the Value is an  Int.
I would like to know how do I go about getting the properties from the received pn_message_t

Here's what I am currently doing.  But the mapsize is always 0.

              pn_messenger_get(messenger, message);
              pn_data_t *properties = pn_message_properties(message);
              size_t mapsize = pn_data_get_map(properties);

              int x=0;
              for(x =0; x< mapsize/2; x++ )
              {
                  printf("Property: %d\n",pn_data_get_int(properties));
              }

If I enable frame level tracing in Proton-c by setting the PN_TRACE_FRM environment variable I do see that the AMQP properties are making it over the wire.

<- TRANSFER @20 [0, 0, b"\xe1\x11\xe7\x07$F\xb7E\xa55\xb1\x1b\x0f\xaf[\xdd", 0, null, false, null, null, null, null, true] (252) "\x00Sp\xc0\x07\x05@@@@R\x01\x00Sr\xc1U\x06\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01=\x8f\xde\xe8\xae\xa3\x15x-opt-sequence-numberU\x01\xa3\x12x-opt-locked-until\x83\x00\x00\x01=\x8f\xdf\xdc&\x00Ss\xc0/\x0d\xa1 7d497616f2a54fb3b3a3b857443ac17c@@@@@@@@@@@@\x00St\xc1\x1d\x06\xa1\x05FirstT\x01\xa1\x06SecondT\x02\xa1\x05ThirdT\x03\x00Su\xa0;@\x03int\x083http://schemas.microsoft.com/2003/10/Serialization/\x81"


Can someone point me to the correct way to get to the AMQP message properties or point me to a sample that does this.

Thanks,
Arun

Re: Getting AMQP message properties though Proton-C

Posted by Rafael Schloming <rh...@alum.mit.edu>.
You're quite welcome.

You're correct about the type in the dump. It is a value of the pn_type_t
enum. I just changed the code to use the type name instead of the numeric
value, so that should be more obvious in the next release.

--Rafael

On Mon, Mar 25, 2013 at 3:44 PM, Arun Dsouza <ar...@microsoft.com> wrote:

> Thanks a ton Rafael!
> The key was  adding pn_data_next(properties)  to get the cursor on the map.
> The tip about using pn_data_dump was also very helpful. What I get when I
> dump the properties of my message is below.  The type indicates the data
> type as defined by the pn_type_t enum. Is that correct?
>
> {current=0, parent=0}
> Node 1: prev=0, next=0, parent=0, down=2, children=6, type=24 (map[0])
> Node 2: prev=0, next=3, parent=1, down=0, children=0, type=19 ("First")
> Node 3: prev=2, next=4, parent=1, down=0, children=0, type=7 (1)
> Node 4: prev=3, next=5, parent=1, down=0, children=0, type=19 ("Second")
> Node 5: prev=4, next=6, parent=1, down=0, children=0, type=7 (2)
> Node 6: prev=5, next=7, parent=1, down=0, children=0, type=19 ("Third")
> Node 7: prev=6, next=0, parent=1, down=0, children=0, type=7 (3)
>
>
> Thanks,
> Arun
>
> -----Original Message-----
> From: Rafael Schloming [mailto:rhs@alum.mit.edu]
> Sent: Monday, March 25, 2013 9:14 AM
> To: proton@qpid.apache.org
> Subject: Re: Getting AMQP message properties though Proton-C
>
> On Fri, Mar 22, 2013 at 3:01 PM, Arun Dsouza <ar...@microsoft.com>
> wrote:
>
> > I would like to know the correct way to access AMQP message properties
> > through Proton-C. If this the not the right mailing list  for Proton-C
> > usage queries, I apologize and please direct me to the mailing list.
> >
>
> This is a fine place. Sorry for the delay in replying. I've been laid up
> for a few days recovering from a medical procedure last week.
>
>
> >
> > The scenario I have is an interop scenario where I send messages to a
> > Windows Azure Service Bus queue using  the Service Bus .NET API,  and
> > I receive from the queue using the Linux version of the Proton-C
> > client ( Release 0.4 ) While sending messages I set some properties on
> > AMQP message, and I want to get those properties from the Proton-C
> > receiver. The properties are simple key value pairs where the Key is a
> > string and the Value is an  Int.
> > I would like to know how do I go about getting the properties from the
> > received pn_message_t
> >
> > Here's what I am currently doing.  But the mapsize is always 0.
> >
> >               pn_messenger_get(messenger, message);
> >               pn_data_t *properties = pn_message_properties(message);
> >               size_t mapsize = pn_data_get_map(properties);
> >
> >               int x=0;
> >               for(x =0; x< mapsize/2; x++ )
> >               {
> >                   printf("Property: %d\n",pn_data_get_int(properties));
> >               }
> >
>
> For one thing you should actually check that the type of the value you're
> trying to get is a map, e.g. print out pn_data_type(properties) and see if
> that is actually a map. If the data object's cursor happens to be pointing
> to something that is not a map, then get_map will always return 0.
>
> In this case my guess is that you need to do a pn_data_next(properties);
> in order to position the cursor on the map prior to accessing it, however
> you can always do a pn_data_dump(properties); to see exactly what is going
> on.
> If you post the output from that I can provide a little more help. Here's
> my best guess:
>
>   pn_messenger_get(messenger, message);
>   pn_data_t *properties = pn_message_properties(message);
>   // advance the cursor to the first object
>   pn_data_next(properties);
>   // assert that it is the properties map
>   assert(pn_data_type(properties) == PN_MAP);
>   size_t mapsize = pn_data_get_map(properties);
>
>   // enter the properties map
>   pn_data_enter(properties);
>   int x=0;
>   for(x =0; x< mapsize/2; x++ )
>   {
>       printf("Property: %d\n",pn_data_get_int(properties));
>   }
>   // exit the properties map
>   pn_data_exit(properties);
>
> --Rafael
>
>

RE: Getting AMQP message properties though Proton-C

Posted by Arun Dsouza <ar...@microsoft.com>.
Thanks a ton Rafael!
The key was  adding pn_data_next(properties)  to get the cursor on the map. 
The tip about using pn_data_dump was also very helpful. What I get when I dump the properties of my message is below.  The type indicates the data type as defined by the pn_type_t enum. Is that correct?

{current=0, parent=0}
Node 1: prev=0, next=0, parent=0, down=2, children=6, type=24 (map[0])
Node 2: prev=0, next=3, parent=1, down=0, children=0, type=19 ("First")
Node 3: prev=2, next=4, parent=1, down=0, children=0, type=7 (1)
Node 4: prev=3, next=5, parent=1, down=0, children=0, type=19 ("Second")
Node 5: prev=4, next=6, parent=1, down=0, children=0, type=7 (2)
Node 6: prev=5, next=7, parent=1, down=0, children=0, type=19 ("Third")
Node 7: prev=6, next=0, parent=1, down=0, children=0, type=7 (3)
 

Thanks,
Arun

-----Original Message-----
From: Rafael Schloming [mailto:rhs@alum.mit.edu] 
Sent: Monday, March 25, 2013 9:14 AM
To: proton@qpid.apache.org
Subject: Re: Getting AMQP message properties though Proton-C

On Fri, Mar 22, 2013 at 3:01 PM, Arun Dsouza <ar...@microsoft.com> wrote:

> I would like to know the correct way to access AMQP message properties 
> through Proton-C. If this the not the right mailing list  for Proton-C 
> usage queries, I apologize and please direct me to the mailing list.
>

This is a fine place. Sorry for the delay in replying. I've been laid up for a few days recovering from a medical procedure last week.


>
> The scenario I have is an interop scenario where I send messages to a  
> Windows Azure Service Bus queue using  the Service Bus .NET API,  and 
> I receive from the queue using the Linux version of the Proton-C 
> client ( Release 0.4 ) While sending messages I set some properties on 
> AMQP message, and I want to get those properties from the Proton-C 
> receiver. The properties are simple key value pairs where the Key is a 
> string and the Value is an  Int.
> I would like to know how do I go about getting the properties from the 
> received pn_message_t
>
> Here's what I am currently doing.  But the mapsize is always 0.
>
>               pn_messenger_get(messenger, message);
>               pn_data_t *properties = pn_message_properties(message);
>               size_t mapsize = pn_data_get_map(properties);
>
>               int x=0;
>               for(x =0; x< mapsize/2; x++ )
>               {
>                   printf("Property: %d\n",pn_data_get_int(properties));
>               }
>

For one thing you should actually check that the type of the value you're trying to get is a map, e.g. print out pn_data_type(properties) and see if that is actually a map. If the data object's cursor happens to be pointing to something that is not a map, then get_map will always return 0.

In this case my guess is that you need to do a pn_data_next(properties); in order to position the cursor on the map prior to accessing it, however you can always do a pn_data_dump(properties); to see exactly what is going on.
If you post the output from that I can provide a little more help. Here's my best guess:

  pn_messenger_get(messenger, message);
  pn_data_t *properties = pn_message_properties(message);
  // advance the cursor to the first object
  pn_data_next(properties);
  // assert that it is the properties map
  assert(pn_data_type(properties) == PN_MAP);
  size_t mapsize = pn_data_get_map(properties);

  // enter the properties map
  pn_data_enter(properties);
  int x=0;
  for(x =0; x< mapsize/2; x++ )
  {
      printf("Property: %d\n",pn_data_get_int(properties));
  }
  // exit the properties map
  pn_data_exit(properties);

--Rafael


Re: Getting AMQP message properties though Proton-C

Posted by Rafael Schloming <rh...@alum.mit.edu>.
On Fri, Mar 22, 2013 at 3:01 PM, Arun Dsouza <ar...@microsoft.com> wrote:

> I would like to know the correct way to access AMQP message properties
> through Proton-C. If this the not the right mailing list  for Proton-C
> usage queries, I apologize and please direct me to the mailing list.
>

This is a fine place. Sorry for the delay in replying. I've been laid up
for a few days recovering from a medical procedure last week.


>
> The scenario I have is an interop scenario where I send messages to a
>  Windows Azure Service Bus queue using  the Service Bus .NET API,  and I
> receive from the queue using the Linux version of the Proton-C client (
> Release 0.4 )
> While sending messages I set some properties on AMQP message, and I want
> to get those properties from the Proton-C receiver. The properties are
> simple key value pairs where the Key is a string and the Value is an  Int.
> I would like to know how do I go about getting the properties from the
> received pn_message_t
>
> Here's what I am currently doing.  But the mapsize is always 0.
>
>               pn_messenger_get(messenger, message);
>               pn_data_t *properties = pn_message_properties(message);
>               size_t mapsize = pn_data_get_map(properties);
>
>               int x=0;
>               for(x =0; x< mapsize/2; x++ )
>               {
>                   printf("Property: %d\n",pn_data_get_int(properties));
>               }
>

For one thing you should actually check that the type of the value you're
trying to get is a map, e.g. print out pn_data_type(properties) and see if
that is actually a map. If the data object's cursor happens to be pointing
to something that is not a map, then get_map will always return 0.

In this case my guess is that you need to do a pn_data_next(properties); in
order to position the cursor on the map prior to accessing it, however you
can always do a pn_data_dump(properties); to see exactly what is going on.
If you post the output from that I can provide a little more help. Here's
my best guess:

  pn_messenger_get(messenger, message);
  pn_data_t *properties = pn_message_properties(message);
  // advance the cursor to the first object
  pn_data_next(properties);
  // assert that it is the properties map
  assert(pn_data_type(properties) == PN_MAP);
  size_t mapsize = pn_data_get_map(properties);

  // enter the properties map
  pn_data_enter(properties);
  int x=0;
  for(x =0; x< mapsize/2; x++ )
  {
      printf("Property: %d\n",pn_data_get_int(properties));
  }
  // exit the properties map
  pn_data_exit(properties);

--Rafael