Automatic Redelivery Counting
If the client is using automatic redelivery counting mode, the Broker automatically updates the redelivery counter when delivers an event to a client. As in manual mode, the redelivery counter is set to zero the first time the event is delivered to a client. If the Broker resends the event to the client, it increments the event's redelivery counter before sending the event out.
The way in which a client uses automatic redelivery counting mode is nearly the same as it would use manual mode. As you can see by the following snippet, the code is identical to the manual mode example on above in
Manual Redelivery Counting, except that 1) the client sets the connection descriptor automatic mode and 2) it omits the call to the
incrementRedeliveryCount method.
static String broker_host = "localhost";
static String broker_name = null;
static String client_group = "sample";
BrokerConnectionDescriptor d;
BrokerClient c;
BrokerEvent e;
long rsn;
boolean rd_mode = true;
int rd_count;
. . .
/* -----------------------------------------------*/
/* Create descriptor and enable Automatic Redelivery */
try {
d = new BrokerConnectionDescriptor;
d.setAutomaticRedeliveryCount(rd_mode);
} catch (BrokerException ex) {
System.out.println("Error on create descriptor\n"+ex);
return;
}
/* ----------------------------------------------- */
/* Create client using connection descriptor */
try {
c = new BrokerClient(broker_host, broker_name,
null, client_group,
"Subscriber Sample #1",d);
} catch (BrokerException ex) {
System.out.println("Error on create client\n"+ex);
return;
}
. . .
/* -------------------------------------------------*/
/* Get event, update count, pass event to user code */
while (dispatchingDocuments() == true) {
e = BrokerClient.getEvent();
rsn = e.getReceiptSequenceNumber();
rd_count = e.getRedeliveredCount();
if (dispatchToUserCode(e, rd_count) == OK) {
c.acknowledge(rsn);
}
}
. . .
As shown above, your Broker client dispatches the event and the redelivery count to user code. The user code must accept the redelivery count (an integer) and take appropriate steps to process the event if the value of the counter is greater than zero.