18.4. Asynchronous Send Acknowledgments
If you are using a non-transacted session but want a guarantee that every message sent to the server has reached it, then, as discussed in Section 18.2, “Guarantees of Non Transactional Message Sends”, you can configure HornetQ to block the call to send until the server has received the message, persisted it and sent back a response. This works well but has a severe performance penalty - each call to send needs to block for at least the time of a network round trip (RTT) - the performance of sending is thus limited by the latency of the network, not limited by the network bandwidth.
To remedy this, HornetQ provides a feature called asynchronous send acknowledgments. With this feature, HornetQ can be configured to send messages without blocking in one direction and asynchronously getting acknowledgment from the server that the messages were received in a separate stream. By decoupling the send from the acknowledgment of the send, the system is not limited by the network RTT, but is limited by the network bandwidth. Consequently better throughput can be achieved than is possible using a blocking approach, while at the same time having absolute guarantees that messages have successfully reached the server.
The window size for send acknowledgments is determined by the confirmation-window-size parameter on the connection factory or client session factory. refer to Chapter 32, Client Reconnection and Session Reattachment for more info on this.
18.4.1. Asynchronous Send Acknowledgments
To use the feature using the core API, implement the interface
org.hornetq.api.core.client.SendAcknowledgementHandler
and set a handler instance on your ClientSession
.
Send messages as normal using your
ClientSession
, and as messages reach the server, the server will send back an acknowledgment of the send asynchronously. HornetQ calls your handler's sendAcknowledged(ClientMessage message)
method, passing in a reference to the message that was sent.
To enable asynchronous send acknowledgments, make sure
confirmation-window-size
is set to a positive integer value (specified in bytes). For example, 10485760 (10 Mebibytes) .