title: spring amqp-outbound gateway to produce reply from a different thead (Like jms-outbound gateway)
body: <p><strong>Problem statement:</strong></p>
  
  <p>Spring amqp-outbound gateway to produce reply from a different thread (Like jms-outbound gateway, having different queue, correlate the request/response using correlation key). </p>
  
  <p>Unable to correlate the message with this example.</p>
  
  <p><strong>Spring integration</strong> </p>
  
  <pre><code>    &lt;int:gateway id="outboundGateway" service-interface="com.amqp.outbound.gateway.OutboundGateway"     
                          default-reply-channel="defaultReplyChannel" &gt;
          &lt;int:method name="process"   request-channel="inboundRequestChannel"/&gt;
      &lt;/int:gateway&gt;
  
      &lt;int:channel id="defaultReplyChannel"/&gt;
      &lt;int:channel id="inboundRequestChannel"/&gt;
      &lt;int:channel id="enrichedInboundRequestChannel"/&gt;
      &lt;int:channel id="processAuthRequestChannel"/&gt;
      &lt;int:channel id="postProcessorChannel"/&gt;
  
      &lt;int:chain input-channel="inboundRequestChannel" output-channel="enrichedInboundRequestChannel"&gt;
          &lt;int:service-activator id="serviceActivator"
                         ref="ouboundService"  method="createRequest"/&gt;
      &lt;/int:chain&gt;
  
      &lt;int-amqp:outbound-gateway id="outboundGtwyId" header-mapper="headerMapper"
                          request-channel="enrichedInboundRequestChannel"
                          reply-channel="defaultReplyChannel"
                          amqp-template="template" 
                          reply-timeout="30000" 
                          exchange-name="request_exchange" 
                          routing-key="request_exchange_queue"/&gt;
  
      &lt;int-amqp:inbound-channel-adapter id="amqpMessageDriven"  queue-names="request_queue" 
                                   connection-factory="rabbitConnectionFactory"  channel="processAuthRequestChannel"/&gt;
  
      &lt;int:service-activator id="serviceActivator"
                         ref="ouboundService" input-channel="processAuthRequestChannel" output-channel="postProcessorChannel"
                         method="processRequest"/&gt;
  
      &lt;int-amqp:outbound-channel-adapter amqp-template="template" channel="postProcessorChannel" 
              header-mapper="headerMapper" exchange-name="reply_exchange" routing-key="reply_exchange_queue"/&gt;
  
      &lt;bean id="headerMapper" class="org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper"/&gt;
  </code></pre>
  
  <p><strong>Config</strong></p>
  
  <pre><code>@Bean
  public RabbitTemplate template(ConnectionFactory rabbitConnectionFactory){
      final RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory);
      template.setQueue("reply_queue");
      return template;
  }
  
  
  
  @Bean
  public Binding binding(){
      return BindingBuilder.bind(this.queue()).to(this.exchange()).with("request_exchange_queue");
  }
  
  @Bean
  public DirectExchange exchange(){
      return new DirectExchange("request_exchange");
  }
  
  @Bean
  public Queue queue(){
      return new Queue("request_queue", true, false, true);
  }
  
  @Bean
  public Binding bindingReply(){
      return BindingBuilder.bind(this.queue()).to(this.exchange()).with("reply_exchange_queue");
  }
  
  @Bean
  public DirectExchange exchangeReply(){
      return new DirectExchange("reply_exchange");
  }
  
  
  @Bean
  public Queue replyQueue(){
      return new Queue("reply_queue", true, false, true);
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>@Service
  public final class OuboundService {
  
  
      public Message createRequest(String message){
          System.out.println("Inside createRequest : "+ message);
          final String transactionId = UUID.randomUUID().toString();
          final Message builtMessage = MessageBuilder.withBody(message.getBytes())
                  .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
                  .setHeader(AmqpHeaders.CORRELATION_ID, transactionId)
                  .build();
          return builtMessage;
      }
  
  
      public Message processRequest(Message message){
          System.out.println("Inside process Request : "+ new String(message.getBody()));
          System.out.println("Header values : "+message.getMessageProperties().getHeaders());
          final Message result = MessageBuilder.withBody("Successful".getBytes()).copyProperties(message.getMessageProperties())
                                  .copyHeaders(message.getMessageProperties().getHeaders()).build();
          return result;
      }
  
  }
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p>org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler 'outboundGtwyId', and its 'requiresReply' property is set to true.</p>
  
  <p><strong>GitHub source code (Resolved Solution)</strong> </p>
  
  <p><a href="https://github.com/kingkongprab/spring-amqp-outbound-gateway" rel="nofollow noreferrer">https://github.com/kingkongprab/spring-amqp-outbound-gateway</a></p>