title: Scheduled/Delay messaging in Spring AMQP RabbitMq
body: <p>I am struggling hard to find out the way for scheduled/Delaying messages in Spring AMQP/Rabbit MQ.<br>After hell lot of searching still I am not able to do that in Spring AMQP. Can someone please tell me how to do <b>x-delay</b> in Spring AMQP.<br>I want to Delay a message if some exception occurs in the consumer side. RabbitMQ says to add x-delay and install the plugin which I have already done, but still messages is comming immediately without any delay</p>
  
  <p><br><br>I am getting this in message<br>
  Received &lt;(Body:'[B@60a4ae5f(byte[26])'MessageProperties [headers={x-delay=15000} </p>
  
  <pre><code> @Bean
  ConnectionFactory connectionFactory(){
  
      CachingConnectionFactory connectionFactory=new CachingConnectionFactory("127.0.0.1");
      connectionFactory.setUsername("guest");
      connectionFactory.setPassword("guest");
      connectionFactory.setPort(1500);
      connectionFactory.setPublisherReturns(true);
      return connectionFactory;
  
  }
  
  @Bean
  Binding binding(@Qualifier("queue")Queue queue, DirectExchange exchange) {
      return new Binding(queue.getName(), Binding.DestinationType.QUEUE, exchange.getName(), queue.getName(), null);
      //return BindingBuilder.bind(queue).to(exchange).with(queueName);   
  }
  
  @Bean
  DirectExchange exchange() {
      DirectExchange exchange=new DirectExchange("delay-exchange");
      return exchange;
  }
  </code></pre>
  
  <p>Consumer---<br>
      @Override</p>
  
  <pre><code>public void onMessage(Message message, Channel channel) throws Exception {
  
      System.out.println("Received &lt;" + message+ "&gt;" +rabbitTemplate);
  
      if(i==1){
          AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder();
          Map&lt;String,Object&gt; headers = message.getMessageProperties().getHeaders();
          headers.put("x-delay", 15000);
          props.headers(headers);
          i++;
          channel.basicPublish(message.getMessageProperties().getReceivedExchange(), message.getMessageProperties().getReceivedRoutingKey(),
                  props.build(), message.getBody());
      }
      }
  </code></pre>