Consuming Messages in Transactions
To consume Guaranteed messages in a transaction, a client must create a consumer flow within the transacted session to bind to the destination endpoint that the messages are spooled to.
Guaranteed messages can then be received from the destination endpoint through the consumer flow either:
- asynchronously, through a message receive callback for the Solace C API.
- synchronously, through individual receive calls. The calls required to synchronously consume messages in a transaction are listed below.
Consumers in a transacted session function the same as those in a non‑transacted session, except that the messages they receive are only acknowledged, and subsequently removed from the event broker, when a successful commit occurs for the transacted session. For example, calling solClient_flow_sendAck() (for the Solace C API) has no effect on transacted sessions. For information on how to receive Guaranteed messages synchronously or asynchronously, see Receiving Guaranteed Messages.
For the Solace C API, when a consumer flow is created, it is in a start state. The start/stop state of a consumer flow can be set through the flow properties.
To create a consumer flow in a transacted session in the Solace C API, use solClient_transactedSession_createFlow(...).
To synchronously consume messages in a transaction in the Solace C API, use solClient_flow_receiveMsg(...). This receives a message from the specified flow. It waits until it reaches a specified timeout value or a message is received. If the timeout value is 0, there is no wait. A client application must later call solClient_msg_free() on the received message to release it.
When the following situations occur after the messages are consumed in a transaction, but before a commit is made, those messages are still successfully committed:
- The messages are removed from the event broker by an administrative action (that is, the messages are deleted from the spool).
- The messages’ TTLs have expired. (Note that the commit succeeds whether or not expired messages are moved to a dead message queue (DMQ).)