On Fri, Mar 17, 2023 at 8:45 PM Mendez, Raymond <raymond.men...@dell.com.invalid> wrote:
> Hi, > > I'm using the qpid proton python 0.34 client and was curious about the > on_accepted event handler. Is there a way to know *which* message was > accepted? Will it always be the message last sent, or can they be accepted > in a different order than sent? I think I read in the C++ documentation > that sessions ensure sequential message handling. Perhaps I need to > leverage those? > > To summarize my particular use case, I have an on_message handler that > will reply to incoming messages and I'd like to accept and settle the > incoming message (and update a local outbox) only after its corresponding > reply has been accepted. > > Hope my question makes sense and thank you in advance! > Hi, I'll try to put forward the general idea. I can try to put together a sample program if it proves necessary. The idea is that when you send the message, you either create your own (unique) tag, or store the "delivery tag" automatically assigned to that message by proton, and in your `on_accepted(event)` handler you examine the `event`, look at the delivery tag in it, and that's how you find to which message this accept event pertains to. Specifically, the `send(obj, tag=None)` method on a Sender [1] takes an optional `tag` parameter which is where you can provide your own delivery tag. There is a `delivery_tag()` method on Sender which generates a suitable tag for you (every call to it increments the number it returns by one) [2] In your `on_accepted(event)`, the `event` contains a `delivery` [3] which holds the `tag` value with which the message was sent [4]. The db-send example does this. See lines 76 and 82 in https://github.com/apache/qpid-proton/blob/34b4d930d9a4beaa7728870e215a43880e3e4d07/python/examples/db_send.py#L70-L88. The first line sets the tag as a message is sent, and the second checks its value in the handler. [1] https://qpid.apache.org/releases/qpid-proton-0.34.0/proton/python/docs/proton.html#proton.Sender.send [2] https://qpid.apache.org/releases/qpid-proton-0.38.0/proton/python/docs/proton.html#proton.Sender.delivery_tag (it does not have a helpful docstring in 0.34) [3] https://qpid.apache.org/releases/qpid-proton-0.34.0/proton/python/docs/proton.html#proton.Event.delivery [4] https://qpid.apache.org/releases/qpid-proton-0.34.0/proton/python/docs/proton.html#proton.Delivery.tag -- Mit freundlichen Grüßen / Kind regards Jiri Daněk