Acknowledging Messages
For each message delivered on a subscription, AMPS counts the message
against the subscription backlog until the message is explicitly
acknowledged. In addition, when a queue specifies at-least-once
delivery, AMPS retains the message in the queue until the message
expires or until the message has been explicitly acknowledged and
removed from the queue. From the point of view of the AMPS server,
acknowledgment is implemented as a sow_delete
from the queue with
the bookmarks of the messages to remove. The AMPS JavaScript client provides
several ways to make it easier for applications to create and send the
appropriate sow_delete
.
Automatic Acknowledgment
The AMPS client allows you to specify that messages should be automatically acknowledged. When this mode is on, AMPS acknowledges the message automatically if the message handler returns without throwing an exception.
AMPS batches acknowledgments created with this method, as described in the following section.
To enable automatic acknowledgment, use the Client.autoAck()
method.
client.autoAck(true); // enable AutoAck
Message Convenience Method
The AMPS JavaScript client provides a convenience method, Client.ack()
,
on delivered messages. When the application is finished with the message,
the application simply calls Client.ack()
on the message.
For messages that originated from a queue with at-least-once
semantics, this adds the bookmark from the message to the batch of
messages to acknowledge. For other messages, this method has no effect.
// Add the message to the next acknowledgment batch
client.ack(message);