You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by Andreas Welchlin <an...@welchlin.de> on 2014/12/19 19:23:26 UTC
Read AMQP Properties using proton-c
Hello,
I read AMQP messages using Proton 0.7 c-api which was sent via the Qpid
C++ Message Broker (V0.28). I can read the message content and
attributes like the correlation id or the user id with no problems. But
it was not possible to read the properties of the message.
The code:
---------------------------------------------------------------------------
pn_data_t * dataPtr = pn_message_properties(messagePtr);
pn_data_next(dataPtr);
if (pn_data_type(dataPtr) != PN_MAP)
printf("properties are no map\n"); // on the console it says
that it is no map
size_t mapsize = pn_data_get_map(dataPtr);
pn_data_enter(dataPtr);
for (int idx = 0; idx < mapsize/2; ++idx)
{
printf("Property: %s\n", pn_data_get_string(dataPtr));
}
pn_data_exit(dataPtr);
---------------------------------------------------------------------------
The output:
properties are no map
mapsize: 0
After the code above failed I tried:
pn_data_dump(dataPtr);
The output is also empty, is says:
{current=0, parent=0}
But when I use the Qpid C++ Messaging Api (V0.28)i to read the same
message I get properties:
----------------------------------------------------------
x-amqp-absolute-expiry-time..: 0
x-amqp-creation-time..: 0
x-amqp-first-acquirer..: True
x-amqp-group-sequence..: 0
x-amqp-message-annotations..: {qpid.msg_sequence:30}
x-amqp-to..: amqp://127.0.0.1:5672/testtopic
----------------------------------------------------------
So somehow I missed something but honestly I have no clue what I am
doing wrong.
Can someone give me a hint?
Regards,
Andreas
Re: Read AMQP Properties using proton-c
Posted by Andreas Welchlin <an...@welchlin.de>.
Hello Rafael,
thank you! You are perfectly right. It works now since I put some real
properties into the message.
It was hard to find an example how to read the property map. So here it is.
Maybe some other users find it helpful (it is C++ but its easy to
convert to C):
/**
* Helper which converts pn_bytes_t to a string
*/
std::string toStr(const pn_bytes_t &bytes)
{
return std::string(bytes.start, bytes.size);
}
/**
* Helper which converts pn_data_t to a string using pn_data_get_string.
*/
std::string toStr(pn_data_t *dataPtr)
{
if (dataPtr == 0)
throw std::runtime_error("toStr(): dataptr is null");
pn_bytes_t bytes = pn_data_get_string(dataPtr);
return toStr(bytes);
}
void dump(pn_message_t * messagePtr)
{
printf("Dump Properties:\n");
pn_data_t * dataPtr = pn_message_properties(messagePtr);
// advance the cursor to the first object
pn_data_next(dataPtr);
// assert that it is the properties map
if (pn_data_type(dataPtr) != PN_MAP)
throw std::runtime_error("properties are no map");
size_t mapsize = pn_data_get_map(dataPtr);
// enter the properties map
pn_data_enter(dataPtr);
for (int idx = 0; idx < mapsize / 2; ++idx)
{
pn_data_next(dataPtr);
printf("Key: %s\n", toStr(pn_data_get_string(dataPtr)).c_str());
pn_data_next(dataPtr);
printf("Value: %s\n", toStr(pn_data_get_string(dataPtr)).c_str());
}
// exit the properties map
pn_data_exit(dataPtr);
}
Regards,
Andreas
On 12/20/2014 01:07 AM, Rafael Schloming wrote:
> Hi Andreas,
>
> The x-amqp-foo output you see reported by the messaging API actually
> correspond to message header values which are not the same thing as message
> properties. There should be specific accessors on the message for all of
> those fields, e.g. pn_message_get/set_creation_time(...).
>
> --Rafael
>
> On Fri, Dec 19, 2014 at 1:23 PM, Andreas Welchlin <an...@welchlin.de>
> wrote:
>> Hello,
>>
>> I read AMQP messages using Proton 0.7 c-api which was sent via the Qpid
>> C++ Message Broker (V0.28). I can read the message content and attributes
>> like the correlation id or the user id with no problems. But it was not
>> possible to read the properties of the message.
>>
>> The code:
>>
>> ------------------------------------------------------------
>> ---------------
>> pn_data_t * dataPtr = pn_message_properties(messagePtr);
>> pn_data_next(dataPtr);
>> if (pn_data_type(dataPtr) != PN_MAP)
>> printf("properties are no map\n"); // on the console it says that
>> it is no map
>>
>> size_t mapsize = pn_data_get_map(dataPtr);
>> pn_data_enter(dataPtr);
>> for (int idx = 0; idx < mapsize/2; ++idx)
>> {
>> printf("Property: %s\n", pn_data_get_string(dataPtr));
>> }
>> pn_data_exit(dataPtr);
>> ------------------------------------------------------------
>> ---------------
>>
>> The output:
>>
>> properties are no map
>> mapsize: 0
>>
>>
>> After the code above failed I tried:
>>
>> pn_data_dump(dataPtr);
>>
>> The output is also empty, is says:
>>
>> {current=0, parent=0}
>>
>>
>>
>> But when I use the Qpid C++ Messaging Api (V0.28)i to read the same
>> message I get properties:
>> ----------------------------------------------------------
>> x-amqp-absolute-expiry-time..: 0
>> x-amqp-creation-time..: 0
>> x-amqp-first-acquirer..: True
>> x-amqp-group-sequence..: 0
>> x-amqp-message-annotations..: {qpid.msg_sequence:30}
>> x-amqp-to..: amqp://127.0.0.1:5672/testtopic
>> ----------------------------------------------------------
>>
>>
>> So somehow I missed something but honestly I have no clue what I am doing
>> wrong.
>>
>> Can someone give me a hint?
>>
>> Regards,
>> Andreas
>>
>>
>>
>>
>>
>>
Re: Read AMQP Properties using proton-c
Posted by Rafael Schloming <rh...@alum.mit.edu>.
Hi Andreas,
The x-amqp-foo output you see reported by the messaging API actually
correspond to message header values which are not the same thing as message
properties. There should be specific accessors on the message for all of
those fields, e.g. pn_message_get/set_creation_time(...).
--Rafael
On Fri, Dec 19, 2014 at 1:23 PM, Andreas Welchlin <an...@welchlin.de>
wrote:
>
> Hello,
>
> I read AMQP messages using Proton 0.7 c-api which was sent via the Qpid
> C++ Message Broker (V0.28). I can read the message content and attributes
> like the correlation id or the user id with no problems. But it was not
> possible to read the properties of the message.
>
> The code:
>
> ------------------------------------------------------------
> ---------------
> pn_data_t * dataPtr = pn_message_properties(messagePtr);
> pn_data_next(dataPtr);
> if (pn_data_type(dataPtr) != PN_MAP)
> printf("properties are no map\n"); // on the console it says that
> it is no map
>
> size_t mapsize = pn_data_get_map(dataPtr);
> pn_data_enter(dataPtr);
> for (int idx = 0; idx < mapsize/2; ++idx)
> {
> printf("Property: %s\n", pn_data_get_string(dataPtr));
> }
> pn_data_exit(dataPtr);
> ------------------------------------------------------------
> ---------------
>
> The output:
>
> properties are no map
> mapsize: 0
>
>
> After the code above failed I tried:
>
> pn_data_dump(dataPtr);
>
> The output is also empty, is says:
>
> {current=0, parent=0}
>
>
>
> But when I use the Qpid C++ Messaging Api (V0.28)i to read the same
> message I get properties:
> ----------------------------------------------------------
> x-amqp-absolute-expiry-time..: 0
> x-amqp-creation-time..: 0
> x-amqp-first-acquirer..: True
> x-amqp-group-sequence..: 0
> x-amqp-message-annotations..: {qpid.msg_sequence:30}
> x-amqp-to..: amqp://127.0.0.1:5672/testtopic
> ----------------------------------------------------------
>
>
> So somehow I missed something but honestly I have no clue what I am doing
> wrong.
>
> Can someone give me a hint?
>
> Regards,
> Andreas
>
>
>
>
>
>