Just FYI, what you are doing isn't strictly speaking transactional. If your
client dies after it has sent the processed message to the outbox, but
before it has acknowledged the message from the inbox, then the message
from the inbox will end up getting processed again and you may therefore
see a duplicate entry in your outbox. That might be perfectly fine if your
application can be made to handle duplicates, but if for some reason it
can't then you will need a full fledged transaction which isn't something
you can do via the messenger API (yet).

--Rafael


On Wed, Feb 19, 2014 at 3:09 PM, Shearer, Davin <dshea...@novetta.com>wrote:

> Ok, I think I've found the solution to this.
>
> I want to treat the period from recv to send to be transactional.  So
> here's what I've got:
>
> pn_messenger_t * pMessenger...
> pn_message_t * pMessage(pn_message());
>
> ... recv side ...
>
> /* Set incoming window to 1 message */
> pn_messenger_set_incoming_window(pMessenger, 1);
> /* Fetch up to 1 message */
> pn_messenger_recv(pMessenger, 1);
> /* Pull the message into application space */
> pn_messenger_get(pMessenger, pMessage);
> /* Extract the body */
> pn_data_t * pBody = pn_message_body(pMessage);
> pn_data_next(pBody);
> pn_bytes_t bytes = pn_data_get_bytes(pBody);
>
> ... process the data ...
>
> .. send side ...
>
> address and populate message body...
> /* Put message into the send queue */
> pn_messenger_put(pMessenger, pMessage);
> /* Send everything in the queue */
> pn_messenger_send(pMessenger, -1);
> /* Acknowledge the receive window, expunging the received message from the
> recv queue */
> pn_messenger_accept(pMessenger, pn_messenger_incoming_tracker(pMessenger),
> PN_CUMULATIVE);
>
>
> Tested it and it seems to be working as expected!  Much respect for the
> v0.6 proton API.
>

Reply via email to