简体   繁体   English

Spring Boot @JmsListener 拦截器

[英]Spring Boot @JmsListener Interceptor

In my application I have messages moving from one queue to another, and I want to add message ID in my logs.在我的应用程序中,我有消息从一个队列移动到另一个队列,我想在我的日志中添加消息 ID。 I am trying to figure out if I can intercept message before being actually processed and set message ID in MDC fields so that I can track this message across all the queues.我想弄清楚我是否可以在实际处理之前拦截消息并在 MDC 字段中设置消息 ID,以便我可以跨所有队列跟踪此消息。 I have not had success so far.到目前为止我还没有成功。 Is there any existing solution?有没有现成的解决方案?

That works but then I cannot access message attributes.那行得通,但是我无法访问消息属性。 Is there any message context somewhere in jms components which I can override or access to get message attibutes for logging? jms 组件中的某处是否有任何消息上下文,我可以覆盖或访问这些消息上下文以获取日志记录的消息属性?

You can either add the raw JMS Message (or just the message id property) as an additional parameter to the @JmsListener (and access it with invocation.getArguments() ) or you can wrap the entire listener adapter instead of just your listener bean.您可以将原始 JMS Message (或仅消息 id 属性)作为附加参数添加到@JmsListener (并使用invocation.getArguments()访问它),或者您可以包装整个侦听器适配器,而不仅仅是您的侦听器 bean。 Use the container registry to get a reference to the container, then container.setMessageListener(wrap(container.getMessageListener()));使用容器注册表获取对容器的引用,然后是container.setMessageListener(wrap(container.getMessageListener())); . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM