【问题标题】:Retrieve JMS Headers right after the message is sent without consuming the message在发送消息后立即检索 JMS 标头而不使用消息
【发布时间】:2017-12-29 05:27:53
【问题描述】:

如何在发送消息但不消费消息后检索 JMS 消息标头?

这是我的消息发送代码

jmsTemplate.convertAndSend(que, text, message -> {

       LOGGER.info("setting JMS Message header values");    
       message.setStringProperty(RequestContext.HEADER_ID, id);
     //  LOGGER.info(message.getJMSMessageId()); -- this gives a null value here
       return message;
 });

只有在消息发布到队列后才会生成消息头,所以在使用 MessagePostProcessor 时是否有一种简单的方法来检索 JMS 消息头?

我已经提到了链接 - herehere 但没有太多帮助:(

【问题讨论】:

    标签: spring activemq spring-jms jmstemplate


    【解决方案1】:

    在实际发送消息之前,您无法获取JmsMessageID 标头;后处理器只允许您在发送之前修改转换后的消息。

    但是,您的第二个链接应该可以正常工作,因为它保存了对您以后可以访问的消息的引用。

    编辑

    确认:

    @SpringBootApplication
    public class So48001045Application {
    
        public static void main(String[] args) {
            SpringApplication.run(So48001045Application.class, args).close();
        }
    
        @Bean
        public ApplicationRunner runner(JmsTemplate template) {
            return args -> {
                final AtomicReference<Message> msg = new AtomicReference<>();
                template.convertAndSend("foo", "bar", m -> {
                    msg.set(m);
                    return m;
                });
                System.out.println(msg.get().getJMSMessageID());
            };
        }
    
    }
    

    ID:host.local-61612-1514496441253-4:1:1:1:1
    

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2020-12-28
      相关资源
      最近更新 更多