{"id":561,"date":"2011-01-17T10:56:29","date_gmt":"2011-01-17T08:56:29","guid":{"rendered":"http:\/\/mcl.jogger.pl\/2011\/01\/17\/jms-redelivery-with-activemq-and-servicemix\/"},"modified":"2023-03-23T13:08:54","modified_gmt":"2023-03-23T12:08:54","slug":"jms-redelivery-with-activemq-and-servicemix","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2011\/01\/17\/jms-redelivery-with-activemq-and-servicemix\/","title":{"rendered":"JMS redelivery with ActiveMQ and Servicemix"},"content":{"rendered":"<p>The other day I felt a compelling need to implement a JMS redelivery scenario. The exact scenario I&#8217;d been trying to handle was:<\/p>\n<ol>\n<li>my message is in an ActiveMQ queue or topic<\/li>\n<li>its processing fails, because of some exception &#8211; ie. database access exception due to server nonavailability<\/li>\n<li>since we get an exception, the message is not handled properly, we may want to retry processing attempt some time later<\/li>\n<li>of course, for the redelivery to happen we need the message to stay in the ActiveMQ queue &#8211; fetching messages from the queue will be stopped until the redelivery succeeds or expires<\/li>\n<\/ol>\n<p>See how this can be done after the jump :)<\/p>\n<p>For this to happen, I&#8217;ve tried implementing Apache Camel route, but as it turns out, Camel fails to deliver facilities for exact JMS redelivery. It is possible to set JMS connection in <em>transacted<\/em> mode, but the redeliveries happen one after another and fixed times.<\/p>\n<p>What I&#8217;ve ended up doing was implement a servicemix-jms endpoint. I&#8217;ve used this configuration for it:<\/p>\n<pre class=\"brush: xml\">\r\n\r\n            activemq\/connectionFactory\r\n\r\n            activemq\/resourceAdapter<\/pre>\n<p>As you can see, we lookup a couple of things in JNDI registry, so you need to have them configured on the Servicemix side &#8211; a sample config presented farther in this entry.<\/p>\n<p>The bean responsible for configuring redelivery settings is <strong>activationSpec<\/strong>. You can set various things with it, like:<\/p>\n<ul>\n<li>initial redelivery delay<\/li>\n<li>maximum number of redeliveries<\/li>\n<li>backoff multiplier<\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<p>What is really important in <em>jms:endpoint<\/em> config for this to work are:<\/p>\n<ul>\n<li><em>processorName=&#8221;jca&#8221;<\/em><\/li>\n<li><em>rollbackOnError=&#8221;true&#8221;<\/em><\/li>\n<\/ul>\n<p>Servicemix should have the following entries in its jndi registry:<\/p>\n<pre class=\"brush: xml\">          \r\n\r\n(...) \r\n<!-- namespaces:-->\r\n       xmlns:jencks=\"http:\/\/jencks.org\/2.0\"\r\n       xmlns:amqra=\"http:\/\/activemq.apache.org\/schema\/ra\" --&gt;<\/pre>\n<p>When the redeliveries are exhausted, message is routed to global Dead Letter Queue called ActiveMQ.DLQ. Since this is a single bag for all the failed messages from all queues, you may want to configure this aspect differently. For example you can tell ActiveMQ to create a single DLQ for each queue. Use this config to achieve it &#8211; the changes should be made to Broker configuration.<\/p>\n<pre class=\"brush: xml\">\r\n\r\n        <!-- Set the following policy on all queues using the '&gt;' wildcard -->\r\n\r\n            <!--               Use the prefix 'DLQ.' for the destination name, and make               the DLQ a queue rather than a topic             -->\r\n\r\n  ...<\/pre>\n<p>More on the subject of redelivieries in ActiveMQ can be found at <a href=\"http:\/\/activemq.apache.org\/message-redelivery-and-dlq-handling.html\">http:\/\/activemq.apache.org\/message-redelivery-and-dlq-handling.html<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"The other day I felt a compelling need to implement a JMS redelivery scenario. The exact scenario I&#8217;d&hellip;\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[186],"class_list":{"0":"post-561","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-message-queue"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":8,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":15619,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/561\/revisions\/15619"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}