我有以下代码:
@JmsListener(destination = "myQueue", containerFactory = "myFactory")
public void receiveMessage(MyClass message) {
service.process(message);
}
现在,我想获取jms消息ID。我知道我可以覆盖MappingJackson2MessageConverter
类来执行此操作,但是可以以更简单的方式执行此操作,例如方法的第二个参数吗?
答案 0 :(得分:2)
使用@Header
注释:
@SpringBootApplication
public class So46794317Application {
public static void main(String[] args) {
SpringApplication.run(So46794317Application.class, args);
}
@Bean
public ApplicationRunner runner(JmsTemplate template) {
return args -> template.convertAndSend("foo", "bar");
}
@JmsListener(destination = "foo")
public void receive(String in, @Header(JmsHeaders.MESSAGE_ID) String messageId) {
System.out.println(in + ", id:" + messageId);
}
}
结果:
bar, id:ID:host.local-50513-1508260336349-4:2:1:1:1