Mensajes programados / retrasados en Spring AMQP RabbitMq
Estoy luchando por encontrar el camino para los mensajes programados / retrasados en Spring AMQP / Rabbit MQ.
Después de mucho buscar todavía no puedo hacer eso en Spring AMQP. ¿Puede alguien decirme cómo hacerlo?x-delay en primavera AMQP.
Quiero retrasar un mensaje si se produce alguna excepción en el lado del consumidor. RabbitMQ dice que agregue x-delay e instale el complemento que ya he hecho, pero aún los mensajes llegan inmediatamente sin demora
Estoy recibiendo esto en el mensaje
Recibido <(Cuerpo: '[B @ 60a4ae5f (byte [26])' MessageProperties [encabezados = {x-delay = 15000}
@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;
}
Consumidor---
@Anular
public void onMessage(Message message, Channel channel) throws Exception {
System.out.println("Received <" + message+ ">" +rabbitTemplate);
if(i==1){
AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder();
Map<String,Object> 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());
}
}