title: Azure Service Bus : Amqp Idle Timeout condition = amqp:link:detach-forced
body: <h2>The error I get:</h2>
  <pre><code>2019-12-09 06:39:33.189 ERROR 107132 --- [http-nio-8082-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jms.IllegalStateException: The MessageProducer was closed due to an unrecoverable error.; nested exception is javax.jms.IllegalStateException: The MessageProducer was closed due to an unrecoverable error.] with root cause
  
  javax.jms.JMSException: Idle link tracker, link qpid-jms:sender:ID:7300953e-f587-4ae3-b9fe-85b84e032554:1:101:1:order-update has been idle for 1800000ms TrackingId:801ab247-3f36-4470-8665-08846eb1c181_G24, SystemTracker:client-link34404815, Timestamp:2019-12-06T21:04:35 [condition = amqp:link:detach-forced]
      at org.apache.qpid.jms.provider.amqp.AmqpSupport.convertToException(AmqpSupport.java:164)
      at org.apache.qpid.jms.provider.amqp.AmqpSupport.convertToException(AmqpSupport.java:117)
      at org.apache.qpid.jms.provider.amqp.AmqpAbstractResource.processRemoteClose(AmqpAbstractResource.java:262)
      at org.apache.qpid.jms.provider.amqp.AmqpProvider.processUpdates(AmqpProvider.java:906)
      at org.apache.qpid.jms.provider.amqp.AmqpProvider.access$1800(AmqpProvider.java:102)
      at org.apache.qpid.jms.provider.amqp.AmqpProvider$17.run(AmqpProvider.java:792)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  <h2>dependencies</h2>
  <pre><code>compile group: 'com.microsoft.azure', name: 'azure-servicebus-spring-boot-starter', version: '0.2.0'
  compile group: 'javax.jms', name: 'javax.jms-api', version: '2.0.1'
  compile group: 'org.apache.qpid', name: 'qpid-jms-client', version: '0.28.0'
  compile group: 'org.apache.camel', name: 'camel-jms', version: '2.24.1'
  compile group: 'org.springframework.integration', name: 'spring-integration-jms', version: '5.0.4.RELEASE'
  </code></pre>
  <h2>jmsConnectionFactory configuration:</h2>
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id=&quot;jmsConnectionFactory&quot; class=&quot;org.springframework.jms.connection.CachingConnectionFactory&quot;&gt;
      &lt;property name=&quot;targetConnectionFactory&quot;&gt;
          &lt;bean class=&quot;org.apache.qpid.jms.JmsConnectionFactory&quot;&gt;
              &lt;constructor-arg value=&quot;${azure.jms.url}&quot; /&gt;
              &lt;property name=&quot;username&quot; value=&quot;${azure.jms.username}&quot; /&gt;
              &lt;property name=&quot;password&quot; value=&quot;${azure.jms.password}&quot; /&gt;
              &lt;property name=&quot;clientID&quot; value=&quot;AltaPay&quot; /&gt;
              &lt;property name=&quot;receiveLocalOnly&quot; value=&quot;true&quot; /&gt;
              &lt;property name=&quot;localMessageExpiry&quot; value=&quot;true&quot; /&gt;
              &lt;property name=&quot;populateJMSXUserID&quot; value=&quot;true&quot; /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name=&quot;exceptionListener&quot;&gt;
          &lt;bean class=&quot;com.lauraashley.microservice.altapay.callback.exception.CustomJMSExceptionListener&quot; /&gt;
      &lt;/property&gt;
      &lt;property name=&quot;sessionCacheSize&quot; value=&quot;10&quot; /&gt;
      &lt;property name=&quot;cacheConsumers&quot; value=&quot;false&quot; /&gt;
  &lt;/bean&gt;
  &lt;bean id=&quot;jmsConfig&quot; class=&quot;org.apache.camel.component.jms.JmsConfiguration&quot;&gt;
      &lt;property name=&quot;connectionFactory&quot; ref=&quot;jmsConnectionFactory&quot; /&gt;
      &lt;property name=&quot;cacheLevelName&quot; value=&quot;CACHE_NONE&quot; /&gt;
  &lt;/bean&gt;
  </code></pre>
  <h2>CustomJMSExceptionListener</h2>
  <pre class="lang-java prettyprint-override"><code>public class CustomJMSExceptionListener implements ExceptionListener {
      
      private static final Logger logger = getLogger(CustomJMSExceptionListener.class);
  
      @Override
      public void onException(JMSException exception) {
          // TODO Auto-generated method stub
          logger.error(&quot;--------------- Catched exception with CustomJMSExceptionListener ---------------&quot;);
          logger.error(&quot;Error code:&quot;+exception.getErrorCode());
          logger.error(&quot;Msg:&quot;+exception.getMessage());
          exception.printStackTrace();
          logger.error(&quot;---------------------------------------------------------------------------------&quot;);
      }
  }
  </code></pre>
  <h2>How I reproduce it</h2>
  <p>First: the CustomJMSExceptionListener is not used, isn't configured ok?</p>
  <p>The application is a eccomerce app on OCC ( oracle cloud commerce ) platform that used java spring-boot services for the payment integration and flow.</p>
  <p>This error occurs when an order exceeds the idle time then the connection with the Azure Service Bus fails and in order to reconnect I must restart the java app, and this is quite a big problem because no more orders can be processed. I read that CachingConnectionFactory has reconnectOnException which by default is true.</p>
  <p>I don't really understand why this happens and what is the solution in order to fix it.</p>