MessageProperties#correlationIdString returns an empty value when correlation ID is set #2424
-
the scene : (needs) I set the id in the message. Then I send it . And I hope to get the id after I receive the message. I have read the source code and success finishing my needs , I just want to report that "bug". due to the limited English ability,I hope I expressed clear.If anything wrong,please just ask me. envenviroment: springboot 1.5.8.RELEASE + amqp-client 4.0.3(jar) (I have already use the latest version , but the jar is still the same) <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.3.2.RELEASE</version>
</dependency> api : I set the correlationData into However, when I received the message , I can't get the correlationId through But I can get the correct answer through
the problem is : the variable, I guess it should be the problem of broker,after updating the client-code , your team forget to update the method,which broker handle the message. here is my Code :
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setBeforePublishPostProcessors(correlationIdProcessor());
rabbitTemplate.setMessagePropertiesConverter(defaultMessagePropertiesConverter());
return rabbitTemplate;
}
@Bean
public MessagePostProcessor correlationIdProcessor(){
MessagePostProcessor messagePostProcessor = new CorrelationAwareMessagePostProcessor() {
@Override
public Message postProcessMessage(Message message, Correlation correlation) {
MessageProperties messageProperties = message.getMessageProperties();
if(correlation instanceof CorrelationData){
String correlationId = ((CorrelationData) correlation).getId();
messageProperties.setCorrelationIdString(correlationId);
}
return message;
}
@Override
public Message postProcessMessage(Message message) throws AmqpException {
return message;
}
};
return messagePostProcessor;
}
@Bean
public MessagePropertiesConverter defaultMessagePropertiesConverter() {
DefaultMessagePropertiesConverter messagePropertiesConverter
= new DefaultMessagePropertiesConverter();
messagePropertiesConverter
.setCorrelationIdPolicy(DefaultMessagePropertiesConverter.CorrelationIdPolicy.STRING);
return messagePropertiesConverter;
}
public void sendMessage(String msg) {
CorrelationData correlationData = new CorrelationData();
String uuid = UUID.randomUUID().toString();
correlationData.setId(uuid);
System.out.println("set the id: " + uuid);
System.out.println("send the message");
rabbitTemplate.convertAndSend(MQConfig.MIAOSHA_EXCHANGE, MQConfig.MIAOSHA_ROUTING_KEY,
this.buildMessage(msg, correlationData.getId()), correlationData);
}
the terminal output: here is the detailed MessageProperties
[headers={}, timestamp=null, messageId=null, userId=null, receivedUserId=null, appId=null, clusterId=null, type=null,
correlationId=[49, 48, 53, 101, 98, 97, 55, 55, 45, 50, 56, 98, 54, 45, 52, 56, 56, 51, 45, 97, 49, 57, 102, 45, 50, 48, 54, 56, 53, 48, 54, 99, 57, 98, 49, 97],
correlationIdString=null,
replyTo=null, contentType=text/plain, contentEncoding=UTF-8, contentLength=0, deliveryMode=null, receivedDeliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=false, receivedExchange=miaosha.directExchange, receivedRoutingKey=secKill, receivedDelay=null, deliveryTag=1, messageCount=0, consumerTag=amq.ctag-5vRvXa8L8E38HZXD2SDbbQ, consumerQueue=miaosha.queue] you can see that correlationIdString is null when correlationId is not null. and here is my github address(if need?) : https://github.com/HermanCho/seckill |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Please ask a question on Spring forum, e.g. StackOverflow tagged with |
Beta Was this translation helpful? Give feedback.
getCorrelationIdString is not something defined in the Java client
and most certainly this is no evidence of a server bug.Please ask a question on Spring forum, e.g. StackOverflow tagged with
spring-amqp
.