如何使用spring-amqp配置rabbitmq回复队列?

时间:2013-11-08 09:42:41

标签: rabbitmq amqp spring-amqp

我们正在尝试使用Spring AMQP在RabbitMQ中进行异步调用,有没有人可以告诉我如何使用spring amqp配置replyqueue,correlationId,(properties)?

    String corrId = java.util.UUID.randomUUID().toString();

 BasicProperties props = new BasicProperties
                                .Builder()
                                .correlationId(corrId)
                                .replyTo(replyQueueName)
                                .build();

 channel.basicPublish("", requestQueueName, props, message.getBytes());

1 个答案:

答案 0 :(得分:1)

我假设你需要使用RabbitTemplate

rabbitTemplate.convertAndSend(requestQueueName, myObj, new MessagePostProcessor() {
   Message postProcessMessage(Message message) throws AmqpException {
      message.getMessageProperties().setReplyTo(replyQueueName);
      return message;  
   }
}, new CorrelationData(corrId));

HTH