title: Spring AMQP: Send reply from POJO listener failure because of missing reply-to property
body: <p>I want to write a simple code sample which sends a message to an exchange, receive it with a listener and send a message back.</p>
  
  <p>This is how I send the message:</p>
  
  <pre><code>private static void pingpong(Object messageListener) throws Exception {
      ConnectionFactory cf = new CachingConnectionFactory("localhost");
  
      // set up the queue, exchange, binding on the broker
      RabbitAdmin admin = new RabbitAdmin(cf);
      Queue queue = new Queue(QUEUE);
      admin.declareQueue(queue);
      TopicExchange exchange = new TopicExchange(EXCHANGE);
      admin.declareExchange(exchange);
      admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*"));
  
      // set up the listener and container
      SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
      container.setMessageListener(messageListener);
      container.setQueueNames(QUEUE);
      container.start();
  
      // send something and receive result.
      RabbitTemplate template = new RabbitTemplate(cf);
      Object result = template.convertSendAndReceive(EXCHANGE, "foo.bar", "ping");
      System.out.println("Received: " + result);
  }
  </code></pre>
  
  <p>The code for the listener:</p>
  
  <pre><code>public static class PingPongReceiver {
      public String handleMessage(String in) {
          System.out.println("Received: " + in);
          return "pong";
      }
  }
  </code></pre>
  
  <p>This is how I call it:</p>
  
  <pre><code>pingpong(new MessageListenerAdapter(new PingPongReceiver()));
  </code></pre>
  
  <p>But sending the reply fails with the following exceptions:</p>
  
  <pre><code>org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:865)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:760)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:680)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:93)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:183)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1345)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:661)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1096)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1080)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$800(SimpleMessageListenerContainer.java:93)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1190)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.amqp.rabbit.listener.adapter.ReplyFailureException: Failed to send reply with payload 'pong'
      at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.handleResult(AbstractAdaptableMessageListener.java:213)
      at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:296)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:757)
      ... 10 more
  Caused by: org.springframework.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
      at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.getReplyToAddress(AbstractAdaptableMessageListener.java:289)
      at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.handleResult(AbstractAdaptableMessageListener.java:209)
      ... 12 more
  </code></pre>
  
  <p>I have problems figuring out how to send the reply using an anonymous, non-durable queue. What am I missing?</p>