You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Kai <so...@gmail.com> on 2021/11/16 12:08:50 UTC

Setting application properties on Message with Qpid Proton Python

Hi,

I am trying to set some application properties on a message to be sent
using Qpid Python 0.36 using the following code:
msg = Message(
                body="the body",
                properties={
                    "status": 200
                },
                address="reply-to-address",
                correlation_id="correlationId",
                content_type="text/plain"
            )

when I send this message then at the consumer side I am not able to
retrieve the "status" from the message's application properties.

Taking a look at the Message class source code it looks to me as if the
properties parameter is not used at all in the Message instance.

Can you shed some light on this?

Regards,
Kai

Re: Setting application properties on Message with Qpid Proton Python

Posted by Kai <so...@gmail.com>.
Aha, that's it! Thanks for the pointer, Robbie :-)

On Tue, Nov 16, 2021 at 5:10 PM Robbie Gemmell <ro...@gmail.com>
wrote:

>
> https://qpid.apache.org/releases/qpid-proton-0.36.0/proton/python/docs/proton.html#proton.int32
> ?
>
> On Tue, 16 Nov 2021 at 15:54, Kai <so...@gmail.com> wrote:
> >
> > Hi Gorden,
> > I have set the PN_TRACE_FRM=1 environment variable and I can see that the
> > "status" property is indeed included in the message sent. However, it
> seems
> > to be encoded as a 64bit integer, i.e. as an AMQP 1.0 long. The consumer,
> > however, expects it to be an AMQP 1.0 int. Is there a way to specify that
> > the value (200) should be encoded as an int instead of a long?
> >
> > Kai
> >
> > On Tue, Nov 16, 2021 at 2:21 PM Gordon Sim <gs...@redhat.com> wrote:
> >
> > > On Tue, Nov 16, 2021 at 12:17 PM Kai <so...@gmail.com> wrote:
> > > > I am trying to set some application properties on a message to be
> sent
> > > > using Qpid Python 0.36 using the following code:
> > > > msg = Message(
> > > >                 body="the body",
> > > >                 properties={
> > > >                     "status": 200
> > > >                 },
> > > >                 address="reply-to-address",
> > > >                 correlation_id="correlationId",
> > > >                 content_type="text/plain"
> > > >             )
> > > >
> > > > when I send this message then at the consumer side I am not able to
> > > > retrieve the "status" from the message's application properties.
> > >
> > > It works for me (sending message above, I can print out the properties
> > > in a receiver and see the status set as expected). If you run the
> > > python program with PN_TRACE_FRM=1, what do you see for the transfer
> > > content?
> > >
> > >
> > > (I see "\x00SpE\x00Ss\xd0\x00\x00\x005\x00\x00\x00\x07@
> > > @\xa1\x10reply-to-address@
> > >
> @\xa1\x0dcorrelationId\xa3\x0atext/plain\x00St\xd1\x00\x00\x00\x15\x00\x00\x00\x02\xa1\x06status\x81\x00\x00\x00\x00\x00\x00\x00\xc8\x00Sw\xa1\x08the
> > > body" using
> > >
> > > #!/usr/bin/env python
> > >
> > > from proton import Message
> > > from proton.handlers import MessagingHandler
> > > from proton.reactor import Container
> > >
> > > class Test(MessagingHandler):
> > >     def __init__(self, url):
> > >         super(Test, self).__init__()
> > >         self.url = url
> > >         self.sent = False
> > >
> > >     def on_start(self, event):
> > >         event.container.create_sender(self.url)
> > >         event.container.create_receiver(self.url)
> > >
> > >     def on_sendable(self, event):
> > >         if not self.sent:
> > >             msg = Message(
> > >                 body="the body",
> > >                 properties={
> > >                     "status": 200
> > >                 },
> > >                 address="reply-to-address",
> > >                 correlation_id="correlationId",
> > >                 content_type="text/plain"
> > >             )
> > >             event.sender.send(msg)
> > >             self.sent = True
> > >
> > >     def on_message(self, event):
> > >         print("properties:", event.message.properties)
> > >         print("body:", event.message.body)
> > >         event.receiver.close()
> > >         event.connection.close()
> > >
> > >     def on_accepted(self, event):
> > >         event.connection.close()
> > >
> > > try:
> > >     Container(Test("localhost/examples")).run()
> > > except KeyboardInterrupt:
> > >     pass
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > >
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: Setting application properties on Message with Qpid Proton Python

Posted by Robbie Gemmell <ro...@gmail.com>.
https://qpid.apache.org/releases/qpid-proton-0.36.0/proton/python/docs/proton.html#proton.int32
?

On Tue, 16 Nov 2021 at 15:54, Kai <so...@gmail.com> wrote:
>
> Hi Gorden,
> I have set the PN_TRACE_FRM=1 environment variable and I can see that the
> "status" property is indeed included in the message sent. However, it seems
> to be encoded as a 64bit integer, i.e. as an AMQP 1.0 long. The consumer,
> however, expects it to be an AMQP 1.0 int. Is there a way to specify that
> the value (200) should be encoded as an int instead of a long?
>
> Kai
>
> On Tue, Nov 16, 2021 at 2:21 PM Gordon Sim <gs...@redhat.com> wrote:
>
> > On Tue, Nov 16, 2021 at 12:17 PM Kai <so...@gmail.com> wrote:
> > > I am trying to set some application properties on a message to be sent
> > > using Qpid Python 0.36 using the following code:
> > > msg = Message(
> > >                 body="the body",
> > >                 properties={
> > >                     "status": 200
> > >                 },
> > >                 address="reply-to-address",
> > >                 correlation_id="correlationId",
> > >                 content_type="text/plain"
> > >             )
> > >
> > > when I send this message then at the consumer side I am not able to
> > > retrieve the "status" from the message's application properties.
> >
> > It works for me (sending message above, I can print out the properties
> > in a receiver and see the status set as expected). If you run the
> > python program with PN_TRACE_FRM=1, what do you see for the transfer
> > content?
> >
> >
> > (I see "\x00SpE\x00Ss\xd0\x00\x00\x005\x00\x00\x00\x07@
> > @\xa1\x10reply-to-address@
> > @\xa1\x0dcorrelationId\xa3\x0atext/plain\x00St\xd1\x00\x00\x00\x15\x00\x00\x00\x02\xa1\x06status\x81\x00\x00\x00\x00\x00\x00\x00\xc8\x00Sw\xa1\x08the
> > body" using
> >
> > #!/usr/bin/env python
> >
> > from proton import Message
> > from proton.handlers import MessagingHandler
> > from proton.reactor import Container
> >
> > class Test(MessagingHandler):
> >     def __init__(self, url):
> >         super(Test, self).__init__()
> >         self.url = url
> >         self.sent = False
> >
> >     def on_start(self, event):
> >         event.container.create_sender(self.url)
> >         event.container.create_receiver(self.url)
> >
> >     def on_sendable(self, event):
> >         if not self.sent:
> >             msg = Message(
> >                 body="the body",
> >                 properties={
> >                     "status": 200
> >                 },
> >                 address="reply-to-address",
> >                 correlation_id="correlationId",
> >                 content_type="text/plain"
> >             )
> >             event.sender.send(msg)
> >             self.sent = True
> >
> >     def on_message(self, event):
> >         print("properties:", event.message.properties)
> >         print("body:", event.message.body)
> >         event.receiver.close()
> >         event.connection.close()
> >
> >     def on_accepted(self, event):
> >         event.connection.close()
> >
> > try:
> >     Container(Test("localhost/examples")).run()
> > except KeyboardInterrupt:
> >     pass
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> >
> >

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


Re: Setting application properties on Message with Qpid Proton Python

Posted by Kai <so...@gmail.com>.
Hi Gorden,
I have set the PN_TRACE_FRM=1 environment variable and I can see that the
"status" property is indeed included in the message sent. However, it seems
to be encoded as a 64bit integer, i.e. as an AMQP 1.0 long. The consumer,
however, expects it to be an AMQP 1.0 int. Is there a way to specify that
the value (200) should be encoded as an int instead of a long?

Kai

On Tue, Nov 16, 2021 at 2:21 PM Gordon Sim <gs...@redhat.com> wrote:

> On Tue, Nov 16, 2021 at 12:17 PM Kai <so...@gmail.com> wrote:
> > I am trying to set some application properties on a message to be sent
> > using Qpid Python 0.36 using the following code:
> > msg = Message(
> >                 body="the body",
> >                 properties={
> >                     "status": 200
> >                 },
> >                 address="reply-to-address",
> >                 correlation_id="correlationId",
> >                 content_type="text/plain"
> >             )
> >
> > when I send this message then at the consumer side I am not able to
> > retrieve the "status" from the message's application properties.
>
> It works for me (sending message above, I can print out the properties
> in a receiver and see the status set as expected). If you run the
> python program with PN_TRACE_FRM=1, what do you see for the transfer
> content?
>
>
> (I see "\x00SpE\x00Ss\xd0\x00\x00\x005\x00\x00\x00\x07@
> @\xa1\x10reply-to-address@
> @\xa1\x0dcorrelationId\xa3\x0atext/plain\x00St\xd1\x00\x00\x00\x15\x00\x00\x00\x02\xa1\x06status\x81\x00\x00\x00\x00\x00\x00\x00\xc8\x00Sw\xa1\x08the
> body" using
>
> #!/usr/bin/env python
>
> from proton import Message
> from proton.handlers import MessagingHandler
> from proton.reactor import Container
>
> class Test(MessagingHandler):
>     def __init__(self, url):
>         super(Test, self).__init__()
>         self.url = url
>         self.sent = False
>
>     def on_start(self, event):
>         event.container.create_sender(self.url)
>         event.container.create_receiver(self.url)
>
>     def on_sendable(self, event):
>         if not self.sent:
>             msg = Message(
>                 body="the body",
>                 properties={
>                     "status": 200
>                 },
>                 address="reply-to-address",
>                 correlation_id="correlationId",
>                 content_type="text/plain"
>             )
>             event.sender.send(msg)
>             self.sent = True
>
>     def on_message(self, event):
>         print("properties:", event.message.properties)
>         print("body:", event.message.body)
>         event.receiver.close()
>         event.connection.close()
>
>     def on_accepted(self, event):
>         event.connection.close()
>
> try:
>     Container(Test("localhost/examples")).run()
> except KeyboardInterrupt:
>     pass
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: Setting application properties on Message with Qpid Proton Python

Posted by Kai <so...@gmail.com>.
Hi Gordon,

when I run that script I do not see anything happening apart from a
blinking cursor.

My python environment is
> python3 --version
Python 3.9.7

On Tue, Nov 16, 2021 at 2:21 PM Gordon Sim <gs...@redhat.com> wrote:

> On Tue, Nov 16, 2021 at 12:17 PM Kai <so...@gmail.com> wrote:
> > I am trying to set some application properties on a message to be sent
> > using Qpid Python 0.36 using the following code:
> > msg = Message(
> >                 body="the body",
> >                 properties={
> >                     "status": 200
> >                 },
> >                 address="reply-to-address",
> >                 correlation_id="correlationId",
> >                 content_type="text/plain"
> >             )
> >
> > when I send this message then at the consumer side I am not able to
> > retrieve the "status" from the message's application properties.
>
> It works for me (sending message above, I can print out the properties
> in a receiver and see the status set as expected). If you run the
> python program with PN_TRACE_FRM=1, what do you see for the transfer
> content?
>
>
> (I see "\x00SpE\x00Ss\xd0\x00\x00\x005\x00\x00\x00\x07@
> @\xa1\x10reply-to-address@
> @\xa1\x0dcorrelationId\xa3\x0atext/plain\x00St\xd1\x00\x00\x00\x15\x00\x00\x00\x02\xa1\x06status\x81\x00\x00\x00\x00\x00\x00\x00\xc8\x00Sw\xa1\x08the
> body" using
>
> #!/usr/bin/env python
>
> from proton import Message
> from proton.handlers import MessagingHandler
> from proton.reactor import Container
>
> class Test(MessagingHandler):
>     def __init__(self, url):
>         super(Test, self).__init__()
>         self.url = url
>         self.sent = False
>
>     def on_start(self, event):
>         event.container.create_sender(self.url)
>         event.container.create_receiver(self.url)
>
>     def on_sendable(self, event):
>         if not self.sent:
>             msg = Message(
>                 body="the body",
>                 properties={
>                     "status": 200
>                 },
>                 address="reply-to-address",
>                 correlation_id="correlationId",
>                 content_type="text/plain"
>             )
>             event.sender.send(msg)
>             self.sent = True
>
>     def on_message(self, event):
>         print("properties:", event.message.properties)
>         print("body:", event.message.body)
>         event.receiver.close()
>         event.connection.close()
>
>     def on_accepted(self, event):
>         event.connection.close()
>
> try:
>     Container(Test("localhost/examples")).run()
> except KeyboardInterrupt:
>     pass
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: Setting application properties on Message with Qpid Proton Python

Posted by Gordon Sim <gs...@redhat.com>.
On Tue, Nov 16, 2021 at 12:17 PM Kai <so...@gmail.com> wrote:
> I am trying to set some application properties on a message to be sent
> using Qpid Python 0.36 using the following code:
> msg = Message(
>                 body="the body",
>                 properties={
>                     "status": 200
>                 },
>                 address="reply-to-address",
>                 correlation_id="correlationId",
>                 content_type="text/plain"
>             )
>
> when I send this message then at the consumer side I am not able to
> retrieve the "status" from the message's application properties.

It works for me (sending message above, I can print out the properties
in a receiver and see the status set as expected). If you run the
python program with PN_TRACE_FRM=1, what do you see for the transfer
content?


(I see "\x00SpE\x00Ss\xd0\x00\x00\x005\x00\x00\x00\x07@@\xa1\x10reply-to-address@@\xa1\x0dcorrelationId\xa3\x0atext/plain\x00St\xd1\x00\x00\x00\x15\x00\x00\x00\x02\xa1\x06status\x81\x00\x00\x00\x00\x00\x00\x00\xc8\x00Sw\xa1\x08the
body" using

#!/usr/bin/env python

from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container

class Test(MessagingHandler):
    def __init__(self, url):
        super(Test, self).__init__()
        self.url = url
        self.sent = False

    def on_start(self, event):
        event.container.create_sender(self.url)
        event.container.create_receiver(self.url)

    def on_sendable(self, event):
        if not self.sent:
            msg = Message(
                body="the body",
                properties={
                    "status": 200
                },
                address="reply-to-address",
                correlation_id="correlationId",
                content_type="text/plain"
            )
            event.sender.send(msg)
            self.sent = True

    def on_message(self, event):
        print("properties:", event.message.properties)
        print("body:", event.message.body)
        event.receiver.close()
        event.connection.close()

    def on_accepted(self, event):
        event.connection.close()

try:
    Container(Test("localhost/examples")).run()
except KeyboardInterrupt:
    pass


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