Hi. I'm using ActiveMQ Artemis 2.6.3. Java client, with separate single
ActiveMQ server. (I.E. no HA)
I'm programmatically creating ClientConsumer's on ClientSession's with
autoCommitAcks false, and with a message handler so I can consume
asynchronously. In the message handler, I have it set to a hard fail (i.e.
I'm trying to test a max number of retries). However, in this situation
with a session rollback I get an infinite number of retries. Here's the
gist of my code:
ServerLocator serverLocator =
ActiveMQClient.createServerLocator(appProperties.getArtemis().getUrl());
serverLocator.setConsumerMaxRate(1);
serverLocator.setRetryIntervalMultiplier(4);
ClientSessionfactory clientSessionFactory =
serverLocator().createSessionFactory();
ClientSession clientSession =
clientSessionFactory.createSession(artemisUser, artemisPassword,
false, true, false, false,
ActiveMQClient.DEFAULT_ACK_BATCH_SIZE);
clientSession.createQueue("myqueue", RoutingType.ANYCAST, queueName, null,
true)
MessageConsumer messageHandler = new MessageConsumer(clientSession);
ClientConsumer clientConsumer = clientSession.createConsumer("myqueue");
clientConsumer.setMessageHandler(messageHandler);
clientSession.start();
public class MessageConsumer implements MessageHandler {
// imports / privates missing for brevity
private ClientSession clientSession;
public MessageConsumer(ClientSession clientSession) {
this.clientSession = clientSession;
}
public void onMessage(ClientMessage clientMessage) {
try {
sendTheMessage(clientMessage);
clientMessage.acknowledge();
clientSession.commit();
} catch (Exception e) {
try {
clientSession.rollback();
} catch (ActiveMQException ex) {
ex.printStackTrace();
}
}
}
private void sendTheMessage(ClientMessage clientMessage) {
throw new IllegalArgumentException("test");
}
}
In the ActiveMQ config, I have this:
<address-settings>
<address-setting match="myqueue">
<dead-letter-address>myqueue.DLQ</dead-letter-address>
<expiry-addressmyqueue.ExpiryQueue</expiry-address>
<redelivery-delay>2500</redelivery-delay>
<max-size-bytes>-1</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>PAGE</address-full-policy>
<auto-create-queues>true</auto-create-queues>
<auto-delete-queues>false</auto-delete-queues>
<auto-create-addresses>true</auto-create-addresses>
<auto-delete-addresses>false</auto-delete-addresses>
<auto-create-jms-queues>true</auto-create-jms-queues>
<auto-delete-jms-queues>false</auto-delete-jms-queues>
<auto-create-jms-topics>true</auto-create-jms-topics>
<auto-delete-jms-topics>false</auto-delete-jms-topics>
<max-delivery-attempts>3</max-delivery-attempts>
</address-setting>
</address-settings>
(Condensed from my actual code)
With this setup, the Consumer gets called repeatedly, and I can't figure out
how to stop it. I had tried looking at the
ClientMessage.getDeliveryCount(), but it is always 1.
If I shut down my client and start it up again, then it still loops - but
now the getDeliveryCount() is 2.
And again - then it goes to 3. And - the server will move the message into
the "myqueue.DLQ".
I had originally coded this up using JMS - and with that the retries worked
fine - but I had problems trying to get an overall Consumer limit of 1
message per second per queue, so I pulled that out and went to the Core API
instead. (Besides - came across this tidbit that indicates JMS Template
isn't the greatest since it creates / destroys sessions / producers /
consumers https://activemq.apache.org/components/artemis/documentation/ in
the Performance Tuning section).
What I would really like to see happen is that a max retries can be set on
the client - but I haven't been able to find such a setting.
Is there such a setting? If not, any ideas on how to stop the infinite loop
of consuming the same message?
Thanks!
Bob.
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html