3 Replies Latest reply on Nov 10, 2015 2:08 AM by Kuat Ospanov

    Configuring redelivery delay and maximumRedeliveries when working with AMQ

    Kuat Ospanov Newbie

      Hello. My environments:

      WildFly 8.1. SwitchYard 2.0. Active MQ 5.11.

      I made an SY application which gets messages from queue in ActiveMq message broker. For this task I have added resource adapter in WildFly:

              <subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">
                  <resource-adapters>
                      <resource-adapter id="activemq-rar.rar">
                          <module slot="main" id="org.apache.activemq"/>
                          <transaction-support>XATransaction</transaction-support>
                          <config-property name="ServerUrl">
                              failover:(tcp://sdbo-db:61616)
                          </config-property>
                          <connection-definitions>
                              <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/AMQConnectionFactory" enabled="true" use-java-context="true" pool-name="AMQConnectionFactory">
                                  <xa-pool>
                                      <min-pool-size>1</min-pool-size>
                                      <max-pool-size>20</max-pool-size>
                                      <prefill>false</prefill>
                                      <is-same-rm-override>false</is-same-rm-override>
                                  </xa-pool>
                              </connection-definition>
                          </connection-definitions>
                          <admin-objects>
                              <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="queue/dwh_egov_gueue" use-java-context="true" pool-name="target_queue">
                                  <config-property name="PhysicalName">
                                      dwh_egov_gueue
                                  </config-property>
                              </admin-object>
                          </admin-objects>
                      </resource-adapter>
                  </resource-adapters>
              </subsystem>
      

      In SY I made service with JMS binding:

      JMS.jpg

      As shown above I am not configuring JMS bridge, just directly use queue from SY application.

      The whole diagram looks like:

       

      switchyard.jpg

       

      With that setting I could get messages in my Camel Route.

      And now the problem. When I get Exception during processing message,  the message from the queue 7 times redelivers with fractions of seconds interval and after that message get to DLQ in AMQ.

      But I want to set redeliver count to 10 with 2 mintues interval and only after that put message to DLQ. How it can be done?

      I tried to setting up redeliver options in AMQ:

      .....................     
       <plugins>
                  <redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true">
                      <redeliveryPolicyMap>
                          <redeliveryPolicyMap>
                              <redeliveryPolicyEntries/>
                              <defaultEntry>
                                  <redeliveryPolicy maximumRedeliveries=10" initialRedeliveryDelay="5000" redeliveryDelay="120000"/>
                              </defaultEntry
                          </redeliveryPolicyMap>
                      </redeliveryPolicyMap>
                  </redeliveryPlugin>
              </plugins>
          </broker>
      
      

       

      But it is not helped. I couldn't found any options in WildFly which would affect on queue redelivery in resource-adapters subsystem.

        • 1. Re: Configuring redelivery delay and maximumRedeliveries when working with AMQ
          Kuat Ospanov Newbie

          Also tried this in my standalone-full-ha.xml :

          failover:(tcp://sdbo-db:61616)?jms.redeliveryPolicy.maximumRedeliveries=10&amp;jms.redeliveryPolicy.redeliveryDelay=1200000
          

          But no success.

          Then I tried to change resource adapter from version 5.9 to 5.11, after that I am facing this error in my logs:

          2015-11-04 16:04:44,615 WARN [pool-10-thread-1] o.a.c.c.j.DefaultJmsMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'dwh_egov_gueue' - trying to recover. Cause: Could not commit JMS transaction; nested exception is javax.jms.IllegalStateException: Not a transacted session
          2015-11-04 16:04:44,615 INFO [pool-10-thread-1] o.a.c.c.j.DefaultJmsMessageListenerContainer - Successfully refreshed JMS Connection
          2015-11-04 16:04:50,590 WARN [pool-10-thread-2] o.a.c.c.j.DefaultJmsMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'dwh_egov_gueue' - trying to recover. Cause: Could not commit JMS transaction; nested exception is javax.jms.IllegalStateException: Not a transacted session
          2015-11-04 16:04:50,590 INFO [pool-10-thread-2] o.a.c.c.j.DefaultJmsMessageListenerContainer - Successfully refreshed JMS Connection
          

          It repeates every 6 seconds.

          So in resource adapter version 5.9 I couldn't set maximumRedelivaeries and redeliveryDelay, in 5.11 I am facing error javax.jms.IllegalStateException: Not a transacted session.

          • 2. Re: Configuring redelivery delay and maximumRedeliveries when working with AMQ
            Tomohisa igarashi Master

            When I tried redelivery delay on HornetQ, it was a broker configuration IIRC. You may want to ask it in ActiveMQ community.

            • 3. Re: Configuring redelivery delay and maximumRedeliveries when working with AMQ
              Kuat Ospanov Newbie

              I decided to use latest version of AMQ broker- 5.12. Also I am using AMQ Resource adapter 5.12.

              But using version 5.12 gave me error:

              2015-11-10 11:48:20,487 WARN [pool-10-thread-2] o.a.c.c.j.DefaultJmsMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'dwh_egov_gueue' - trying to recover. Cause: Could not commit JMS transaction; nested exception is javax.jms.IllegalStateException: Not a transacted session
              2015-11-10 11:48:20,487 INFO [pool-10-thread-2] o.a.c.c.j.DefaultJmsMessageListenerContainer - Successfully refreshed JMS Connection
              

              To resolve this error I have added this property in RA.xml in modules($wildflyhomel\modules\system\layers\base\org\apache\activemq\main\META-INF)

                     <config-property>
                        <description>Boolean to configure if user supplied session args should take effect for a session.</description>
                        <config-property-name>useSessionArgs</config-property-name>
                        <config-property-type>java.lang.Boolean</config-property-type>
                        <config-property-value>true</config-property-value>
                     </config-property>
                 <!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
              

               

              After that settings I was able to set maximumRedeliveries

              This is my ServerUrl from standalone-full-ha.xml:

                                  <config-property name="ServerUrl">
                                      failover:(tcp://sdbo-db:61616)?jms.rmIdFromConnectionId=true&amp;jms.redeliveryPolicy.maximumRedeliveries=3
                                  </config-property>
              

              And it works. But redelivery property is not workings. I tried this options in my ServerUrl: jms.redeliveryPolicy.redeliveryDelay=60000&amp;jms.redeliveryPolicy.initialRedeliveryDelay=60000

              As a solution I am using Camel`s OnException clause in my route:

                onException(Exception.class).handled(false)
                .log("exception accured: ${exception.message}")
                .maximumRedeliveries(1)
                .redeliveryDelay(120000)
              

              This allow me make redelivery 3 times with 2 minutes interval. Interesting this is that changing maximumRedeliveries to 3 in Camel Route will make interval minute, it multiplies maximumRedeliveries and redeliveryDelay and the result will be the final redeliveryDelay.

              Also tried to change redelivery delay and maximumRedeliveries in source code in RedeliveryPolicy.java of activemq-client-5.12.0.jar but it also pick up only maximumRedeliveries property, redeliveryDelay  not affected.

              So in maximumRedeliveries can be set on  broker configuration, redelivery using Camel DSL.