title: JMS Outbound Gateway does not work for request-channel: Dispatcher has no subscribers
body: <p>I am working with Spring Integration <code>'4.2.5.RELEASE'</code></p>
  
  <p>I have the following scenario (<em>experiment purposes</em>) for a global flow integration process</p>
  
  <ul>
  <li>Receive Data from a JMS Destination and send a reply</li>
  <li>Do something with the data received</li>
  <li>Send some data to a JMS Destination and receive a reply</li>
  </ul>
  
  <p>About the two first points I have the following:</p>
  
  <pre><code>&lt;!-- From Remote To Local --&gt;           
  
  &lt;int:channel id="requestFromRemoteToLocalChannel" 
               datatype="com.manuel.jordan.message.Message" /&gt;
  
  &lt;int:publish-subscribe-channel id="responseFromRemoteToLocalChannel" 
                                 datatype="com.manuel.jordan.message.Message" /&gt;
  
  &lt;!-- From Local To Remote --&gt;   
  
  &lt;int:channel id="requestFromLocalToRemoteChannel"                       
               datatype="com.manuel.jordan.message.Message" /&gt;
  
  &lt;int:channel id="responseFromLocalToRemoteChannel" 
               datatype="com.manuel.jordan.message.Message" /&gt;
  
  &lt;int:channel id="responseFromLocalToRemoteChannelPost" 
               datatype="com.manuel.jordan.message.Message" /&gt;
  
  &lt;int-jms:inbound-gateway 
           id="gatewayIn"
           request-destination="queueDestinationFromRemoteToLocal"
           default-reply-destination="queueDestinationFromRemoteToLocalReply"                          
           connection-factory="cachingConnectionFactoryForSpringIntegration"
           request-channel="requestFromRemoteToLocalChannel"
           reply-channel="responseFromRemoteToLocalChannel"
  /&gt;
  </code></pre>
  
  <p>followed with two services activators</p>
  
  <pre><code>&lt;int:service-activator 
       id="serviceActivatorReceptorFromRemoteToLocal"
       input-channel="requestFromRemoteToLocalChannel"
       output-channel="responseFromRemoteToLocalChannel"
       ref="messageServerReceptorJmsGatewayEndpoint"
       method="receptorFromRemoteToLocal"
                              &gt;
  &lt;/int:service-activator&gt;
  
  &lt;int:service-activator 
       id="serviceActivatorRemoveReplyFromRemoteToLocal"
       input-channel="responseFromRemoteToLocalChannel"
       output-channel="nullChannel"
       ref="messageServerReceptorJmsGatewayEndpoint"
       method="removeReplyFromRemoteToLocal"
                             &gt;
  &lt;/int:service-activator&gt;
  </code></pre>
  
  <p>Until here all work fine. </p>
  
  <p>Through a <code>JmsTemplate</code> I send data to the <code>queueDestinationFromRemoteToLocal</code> Destination and therefore the <code>int-jms:inbound-gateway</code> through the <code>request-destination</code> which points to the same Destination is able to automatically get the Message and pass it to a service activator and <em>send</em> a reply to other JMS destination and some <code>@JmsListener</code> does its job. </p>
  
  <p>Again until here I am Ok..</p>
  
  <p>The problem is when from this latest service activator I want send some data to a <code>int-jms:outbound-gateway</code>. It to accomplish the third point of the global integration process</p>
  
  <p>Just changing the latest service activator to:</p>
  
  <pre><code>&lt;int:service-activator 
       id="serviceActivatorRemoveReplyFromRemoteToLocal"
       input-channel="responseFromRemoteToLocalChannel"
       output-channel="requestFromLocalToRemoteChannel"
       ref="messageServerReceptorJmsGatewayEndpoint"
       method="removeReplyFromRemoteToLocal"
                             &gt;            
  &lt;/int:service-activator&gt;
  </code></pre>
  
  <p>Practically from <code>output-channel="nullChannel"</code> to <code>output-channel="requestFromLocalToRemoteChannel"</code></p>
  
  <p>And adding:</p>
  
  <pre><code>&lt;int-jms:outbound-gateway 
           id="gatewayOut"
           request-destination="queueDestinationFromLocalToRemote"                              
           reply-destination="queueDestinationFromLocalToRemoteReply"
           connection-factory="selectedConnectionFactory"
           correlation-key="JMSCorrelationID"
           explicit-qos-enabled="true"                        
           delivery-persistent="true"     
           auto-startup="false"               
           request-channel="requestFromLocalToRemoteChannel"
           reply-channel="responseFromLocalToRemoteChannel"
  
                                &gt;
      &lt;int-jms:reply-listener /&gt;
  
  &lt;/int-jms:outbound-gateway&gt; 
  
  &lt;int:service-activator 
       id="serviceActivatorRemoveReplyFromLocalToRemote"
       input-channel="responseFromLocalToRemoteChannel"
       output-channel="nullChannel"
       ref="messageServerReceptorJmsGatewayEndpoint"
       method="removeReplyFromLocalToRemote"
                  &gt;
  
  &lt;/int:service-activator&gt;
  </code></pre>
  
  <p>Enabling:</p>
  
  <pre><code>&lt;logger name="org.springframework.integration"&gt;
      &lt;level value="debug" /&gt;
  &lt;/logger&gt;
  </code></pre>
  
  <p>I can see:</p>
  
  <blockquote>
    <p>31634 [gatewayIn.container-1] DEBUG o.s.i.j.ChannelPublishingJmsMessageListener$GatewayDelegate - failure occurred in gateway sendAndReceive: Dispatcher has no subscribers for channel 'org.springframework.context.annotation.AnnotationConfigApplicationContext@51565ec2.requestFromLocalToRemoteChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers</p>
  </blockquote>
  
  <p>Practically the <code>int-jms:outbound-gateway</code> is <em>not</em> called</p>
  
  <p>What is missing?</p>
  
  <p>Even if I change the <code>requestFromLocalToRemoteChannel</code> from <code>Direct</code> to <code>Queue</code> and add a <code>poller</code> to the <code>int-jms:outbound-gateway</code> nothing happens, the message shown above disappears but the process remains hanged</p>
  
  <p><strong>Note</strong>: <code>int-jms:outbound-gateway</code> uses <code>auto-startup="false"</code> because the <code>connection-factory="selectedConnectionFactory"</code> (It is <strong>non</strong> cached) comes from:</p>
  
  <pre><code>ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
  connectionFactory.setBrokerURL(...);
  connectionFactory.setClientID("localConnectionFactory");
  connectionFactory.setUserName("Manolito - Local");
  connectionFactory.createConnection().start();// By This...
  connectionFactory.setExceptionListener(new ConnectionFactoryExceptionListener());
  return connectionFactory;
  </code></pre>
  
  <p>other settings has been used according with: <a href="http://docs.spring.io/spring-integration/docs/current/reference/html/jms.html#jms-outbound-gateway" rel="nofollow">20.5 Outbound Gateway</a></p>
  
  <p>If I use:</p>
  
  <pre><code>ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
  connectionFactory.setBrokerURL(...);
  connectionFactory.setClientID("localConnectionFactory");
  connectionFactory.setUserName("Manolito - Local");
  //connectionFactory.createConnection().start();
  connectionFactory.setExceptionListener(new ConnectionFactoryExceptionListener());
  return connectionFactory;
  </code></pre>
  
  <p>And <code>auto-startup="true"</code> (it is default anyway) I get:</p>
  
  <blockquote>
    <p>24917 [gatewayIn.container-1] DEBUG o.s.i.j.ChannelPublishingJmsMessageListener$GatewayDelegate - failure occurred in gateway sendAndReceive: nested exception is javax.jms.InvalidClientIDException: Broker: localhost - Client: localConnectionFactory already connected from tcp://127.0.0.1:59497</p>
  </blockquote>
  
  <p><em>Alpha</em></p>
  
  <p>Adding a new </p>
  
  <pre><code>@Bean
  @Conditional(value=ActiveMQConnectionFactoryLocalHostStatusCondition.class)
  public ActiveMQConnectionFactory localConnectionFactoryForSpringIntegration(
              @Value("${activemq.localhost.protocol}") String protocol,
              @Value("${activemq.localhost.address}") String host,
              @Value("${activemq.localhost.port}") String port) throws JMSException {
  
          logger.info("Creating localConnectionFactoryForSpringIntegration...");
  
          ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
          connectionFactory.setBrokerURL(sameUrl like localConnectionFactory);
          connectionFactory.setClientID("localConnectionFactoryForSpringIntegration");
          connectionFactory.setUserName("Manolito - Local ForSpringIntegration");
          //connectionFactory.createConnection().start();
          connectionFactory.setExceptionListener(new ConnectionFactoryExceptionListener());
          return connectionFactory;
      }
  </code></pre>
  
  <p>Here, <code>setClientID</code> and <code>setUserName</code> are news and this <code>localConnectionFactoryForSpringIntegration</code> is used only for below:
  <code>connection-factory="localConnectionFactoryForSpringIntegration"</code></p>
  
  <p>And changing </p>
  
  <pre><code>&lt;int-jms:outbound-gateway 
           id="gatewayOut"
           request-destination="queueDestinationFromLocalToRemote"                              
           reply-destination="queueDestinationFromLocalToRemoteReply"
           connection-factory="localConnectionFactoryForSpringIntegration"
           correlation-key="JMSCorrelationID"
           explicit-qos-enabled="true"                        
           delivery-persistent="true"     
           auto-startup="true"                
  
           request-channel="requestFromLocalToRemoteChannel"
           reply-channel="responseFromLocalToRemoteChannel"
  
                                &gt;
      &lt;int-jms:reply-listener /&gt;
  
  &lt;/int-jms:outbound-gateway&gt; 
  </code></pre>
  
  <p>I get again:</p>
  
  <blockquote>
    <p>[gatewayIn.container-1] DEBUG o.s.i.j.ChannelPublishingJmsMessageListener$GatewayDelegate - failure occurred in gateway sendAndReceive: nested exception is javax.jms.InvalidClientIDException: Broker: localhost - Client: localConnectionFactoryForSpringIntegration already connected from tcp://127.0.0.1:50056</p>
  </blockquote>
  
  <p>Until here: </p>
  
  <ul>
  <li>I have <code>localConnectionFactory</code> and <code>localConnectionFactoryForSpringIntegration</code> pointing to the same <code>BrokerURL</code> </li>
  <li><code>int-jms:outbound-gateway</code> needs a non-cached <code>connection-factory</code></li>
  <li><code>localConnectionFactoryForSpringIntegration</code> has commented <code>connectionFactory.createConnection().start()</code></li>
  <li><code>int-jms:outbound-gateway</code> has <code>auto-startup="true"</code></li>
  </ul>
  
  <p>Seems in some point <code>localConnectionFactoryForSpringIntegration</code> has been started and the <code>int-jms:outbound-gateway</code> throws: </p>
  
  <blockquote>
    <p>localhost - Client: localConnectionFactoryForSpringIntegration already connected from tcp://127.0.0.1:50056</p>
  </blockquote>
  
  <p>Seems something is needed it</p>