if (msgCtx.getProperty(AMQPConstants.AMQP_REPLY_TO_EXCHANGE_NAME) != null){
String replyExchangeName = (String) msgCtx.getProperty(AMQPConstants.AMQP_REPLY_TO_EXCHANGE_NAME);
String replyRoutingKey = msgCtx.getProperty(AMQPConstants.AMQP_REPLY_TO_ROUTING_KEY)!= null?(String) msgCtx.getProperty(AMQPConstants.AMQP_REPLY_TO_ROUTING_KEY):null;
// for fannout exchange or some other custom exchange, the routing key maybe null
msgProps.setReplyTo(new ReplyTo(replyExchangeName,replyRoutingKey));
}
// If it's request/response, then we need to fill in reply to properties and correlation_id
if (waitForResponse){
if (waitForResponse && msgProps.getCorrelationId() == null) {
if (msgCtx.getProperty(AMQPConstants.AMQP_CORELATION_ID) != null){
msgProps.setCorrelationId((String)msgCtx.getProperty(AMQPConstants.AMQP_CORELATION_ID));
}else{
msgProps.setCorrelationId(UUIDGenerator.getUUID());
}
}
if (msgProps.getReplyTo() == null){
//We need to use a temp queue here.
String tempQueueName = "Queue_" + msgProps.getCorrelationId();
synchronized(session){
session.queueDeclare(tempQueueName, null, null, Option.AUTO_DELETE,Option.EXCLUSIVE);
session.queueBind(tempQueueName, "amq.direct", tempQueueName, null);
session.sync();
}
msgProps.replyTo(new ReplyTo("amq.direct",tempQueueName));
}
}
}