Acknowledging Messages Received by Clients
The messaging APIs provide acknowledgments to the Solace event broker for the guaranteed messages that clients receive through a flow. The figure below shows the process of how the guaranteed messages that an application receives through a flow are acknowledged. During this flow, client applications can also send a negative acknowledgment (NACK) for malformed messages or messages that could not be processed.
Acknowledging Received Guaranteed Messages
API Acknowledgments
A Guaranteed message window size limits the number of messages that the API can receive before it must return an acknowledgment to the event broker to indicate that it received the messages in the window. After the API sends this acknowledgment, the Guaranteed message window reopens so that further messages can be sent to the API.
An application can adjust the windowed acknowledgments by changing the default acknowledgment timer and threshold parameters set through the flow properties. For more information, see Important Flow (Message Consumer) Properties). Changing these defaults is not usually required and will change the performance characteristics of a flow.
Application Acknowledgments
One of the two following application acknowledgment modes can be used for acknowledging a message:
- Auto-acknowledgment
- Client acknowledgment
The acknowledgment mode to use is set through one of the flow properties listed below. By default, the auto-acknowledgment mode is used.
In the Solace .NET API, you can set the acknowledgment mode using the FlowProperties.AckMode property. The possible values are:
AutoAck- The API automatically generates application-level acknowledgmentsClientAck- The client application must explicitly send the acknowledgment for each message received
Auto-Acknowledgment Mode
When the auto-acknowledgment mode is used, the API automatically generates application-level acknowledgments.
Client Acknowledgment Mode
When the client acknowledgment mode is used the client must explicitly send an acknowledgment for the message ID of each message received. Optionally, you can use negative acknowledgments as well. For more information, see Negative Acknowledgments for Specific Messages.
To explicitly send a client acknowledgment, call the IFlow.Ack(...) method.
Avoid allowing the number of outstanding unacknowledged messages to become excessively large (for example, 10,000 or more) because the egress message rate from the event broker can start to decline.
Negative Acknowledgments for Specific Messages
You can use negative acknowledgments (NACKs) if you have configured your applications for client acknowledgments (see Client Acknowledgment Mode). When you use NACKs, you can send a settlement outcome to let the event broker know the result from processing a guaranteed message that was received. Based on the settlement outcome, the event broker knows how to handle the message on its queue. You can use the following settlement outcomes:
- ACCEPTED—This ACK notifies the event broker that your client application successfully processed the guaranteed message. When the event broker receives this outcome it removes the message from its queue.
- When you call a settlement function/methods with an outcome of ACCEPTED, it is the same as calling an ACK function/methods in Client Acknowledgment Mode.
- FAILED—This NACK notifies the event broker that your client application did not process the message. When the event broker receives this NACK it attempts to redeliver the message while adhering to delivery count limits.
- REJECTED—This NACK notifies the event broker that your client application could process the message but it was not accepted (for example, failed validation). When the event broker receives this NACK it removes the message from its queue and then moves the message to the dead message queue (DMQ) if it is configured.
Before you can use NACKs, you must add the FAILED, REJECTED, or both outcomes as NACK types when you create the flow to prepare the flow to work with negative acknowledgments. You do not need to add the ACCEPTED outcome because it is always available. If you try to use an outcome that has not been added, you get an error of Required Settlement Outcome Not Supported.
- NACKs can be lost during transit (for example due to unexpected networking issues). Consider this fact as part of the logic for handling messages when you develop your application.
- NACKs are supported on event brokers 10.2.1 and later. If an event broker does not support NACKs, an
InvalidOperationExceptionoccurs during the flow bind request when an outcome is specified.
Using NACKs
For the Solace .NET API, you must set RequiredOutcomeFailed, RequiredOutcomeRejected, or both properties to true to use NACKs. The following sample code shows how to send NACKs using a fictional messageProcessingObject.process() method, which determines the settlement outcome that is sent with the IFlow.Settle() method:
// This code snippet presumes that you have a session and endpoint (queue) already
// Use object instantiation to set the required properties to use NACKs.
FlowProperties flowProps = new FlowProperties
{
AckMode = MessageAckMode.ClientAck,
RequiredOutcomeFailed = true,
RequiredOutcomeRejected = true
};
IFlow flow = session.CreateFlow(flowProps, queue, null,
new EventHandler<MessageEventArgs>((object source, MessageEventArgs args) =>
{
// Process the received message
if (messageProcessingObject.process(args.Message) == 1)
{
// Accept the message
flow.Settle(args.Message.ADMessageId, MessageOutcome.Accepted);
}
else if (messageProcessingObject.process(args.Message) == 3)
{
// Reject the message
flow.Settle(args.Message.ADMessageId, MessageOutcome.Rejected);
}
else
{
// Failed to process the message
flow.Settle(args.Message.ADMessageId, MessageOutcome.Failed);
args.Message.Dispose();
}
}),
new EventHandler<FlowEventArgs>((object source, FlowEventArgs args) =>
{
// Handle flow events
})
);