Warning: A non-numeric value encountered in /home/ricston2/public_html/blogarchive/wp-content/themes/Divi/functions.php on line 5766

While working with XA transactions in  Mule 3, we came across an issue that crops up when the amount of re-deliveries for a message exceeds that specified on the ActiveMQ-XA-Connector. Some investigation into the problem led to the simple solution of configuring the PrefetchPolicy on the ActiveMQ-XA-Connector.

By default, Active MQ pre-fetches a number of messages (more than one at a time), this means that when Mule asks for a message, the message is received together with a number of prefetched messages that are stored locally by Active MQ. In a non-XA environment, this is useful as the next time Mule is ready for another message, Active MQ does not have to ‘hit’ the network, instead it quickly returns an already prefetched message.

However in an XA environment, when a single transaction is completed, the current session is closed and forces the remaining prefetched messages to be ‘rolled back’. The next time Mule requests a message, a message with an incremented redelivery is received. The following stack trace shows that the number of re-deliveries on a message exceeds the maxRedelivery configured on the Active MQ connector:

ERROR 2011-04-27 12:17:52,752 [transactedJmsConnector.receiver.3] org.mule.exception.DefaultSystemExceptionStrategy:
********************************************************************************
Message               : "Message with id "ID:ricston-999ff86-2173-1303899466253-0:1:24:1:1" has been redelivered 7 times on endpoint "jms://communication.heartbeat", which exceeds the maxRedelivery setting of 3 on the connector "transactedJmsConnector". Message payload is of type: ActiveMQTextMessage
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. "Message with id "ID:ricston-999ff86-2173-1303899466253-0:1:24:1:1" has been redelivered 7 times on endpoint "jms://communication.heartbeat", which exceeds the maxRedelivery setting of 3 on the connector "transactedJmsConnector". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
  org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:91 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ricston-999ff86-2173-1303899466253-0:1:24:1:1" has been redelivered 7 times on endpoint "jms://communication.heartbeat", which exceeds the maxRedelivery setting of 3 on the connector "transactedJmsConnector". Message payload is of type: ActiveMQTextMessage
	at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:91)
	at org.mule.transport.jms.XaTransactedJmsMessageReceiver.getMessages(XaTransactedJmsMessageReceiver.java:269)
	at org.mule.transport.jms.XaTransactedJmsMessageReceiver$1.doInTransaction(XaTransactedJmsMessageReceiver.java:171)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

To cater for this, ActiveMQ allows you to configure the prefetch limit. This defines how many messages can be dispatched to a consumer at any given time. Once this prefetch limit is reached, no more messages are dispatched to the consumer and the next message will be dispatched when an acknowledgement that the previous message has been processed is received. Therefore setting the prefetch limit to ‘0’ will only allow dispatching of messages one at a time.

Here is a code sample of the connector configuration in Mule:

The prefetchPolicy attribute is configured by appending “?jms.prefetchPolicy.all=0” to the brokerURL inside the ActiveMQ-XA-Connector.