Spring Coud Sleuth 导致 ActiveMQ/JMS 消息头丢失 [英] Spring Coud Sleuth causing ActiveMQ/JMS message headers to be lost

查看:31
本文介绍了Spring Coud Sleuth 导致 ActiveMQ/JMS 消息头丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

版本:

  • SpringBoot:2.3.12.RELEASE
  • SpringCloud:Hoxton.SR12
  • SpringCloud Starter Sleuth:3.0.3
  • 骆驼:3.4.6

我想将 Sleuth 添加到一个现在使用 ActiveMQ 的预先存在的项目中,以前它是在使用 JMS.当我这样做时,来自 ActiceMQ 消息的值被阻止/删除(一个是文件名",它是 S2 请求的关键值).其他 JMS 值似乎仍然通过.

I want to add Sleuth to a pre-exisitng project that now makes use of ActiveMQ, previosuly it was jusing JMS. When I do, values from the ActiceMQ message get blocked/removed and (one being "filename" which is the key value for S2 requests). Other JMS values still seem to come through OK.

我需要了解为什么非 JMS 值被阻止/删除(我找不到有关导致这种情况发生的原因的任何信息)以防止出现错误.

I need to understand why the non-JMS values are getting blocked/removed (I cannot find any information on what would be causing that to happen) to prevent the errors.

我知道我可以使用 spring.sleuth.messaging.jms.enabled=true 为 JMS 禁用 Sleuth,但继续前进,我希望能够跟踪 ActiveMQ/JMS 代码,以便解决方法并不是特别有吸引力.

I know I can disbale Sleuth for JMS with spring.sleuth.messaging.jms.enabled=true but moving forwards I'd like to be able to trace the ActiveMQ/JMS code, so that workaround isn't particularly attractive.

由于这是预先退出的代码,我也希望尽可能避免重新编写它.

As this is pre-exiting code, I'd also like to avoid having to re-write it if at all possible.

有没有人让 SPring Cloud Sleuth 与 ActiveMQ/JMS 一起工作,并且可以指出哪里出了问题?

Has anyone gotten SPring Cloud Sleuth to work with ActiveMQ/JMS and can maybe point out where things are going wrong?

根据Marcin的初步反应,我们发现以下版本编译&执行,尽管仍然存在重大问题:

Based on the initial response from Marcin, we found that the following version compile & execute, although significant problems do remain:

  • SpringBoot:2.4.8
  • SpringCloud:2020.0.3
  • 骆驼:3.7.5

没有侦探

ActiveMQ 消息详情:

ActiveMQ message details:

日志消息(存在文件名"、CamelAwsS3Etag"等):

Log message ("filename", "CamelAwsS3Etag" etc present):

2021-08-16 10:10:37.889  INFO [MyApp,,] 28775 --- [umer[taskQueue]] taskQueueConsumer: ***HEADERS IN***: {CamelAwsS3ETag=39d029a87fa4c6aaee5f1de643d9f3f6, Content-Type=application/json, filename=_bl001/group0/_bl001-group0-1629104686042.zip, JMSCorrelationID=null, JMSCorrelationIDAsBytes=null, JMSDeliveryMode=2, JMSDestination=queue://taskQueue, JMSExpiration=0, JMSMessageID=ID:server-44053-1629104652998-1:3:1:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1629104686350, JMSType=null, JMSXGroupID=_bl001-group0, JMSXGroupSeq=0, JMSXUserID=null}

有侦探

ActiveMQ 消息详情:

ActiveMQ message details:

日志消息(缺少文件名"、CamelAwsS3Etag"等):

Log message ("filename", "CamelAwsS3Etag" etc are missing):

2021-08-16 10:24:33.821  INFO [MyApp,,] 31553 --- [umer[taskQueue]] taskQueueConsumer: ***HEADERS IN***: {JMSCorrelationID=null, JMSCorrelationIDAsBytes=null, JMSDeliveryMode=2, JMSDestination=queue://taskQueue, JMSExpiration=0, JMSMessageID=ID:server-42561-1629105658959-1:3:1:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1629105675306, JMSType=null, JMSXGroupID=_bl000-group1, JMSXGroupSeq=0, JMSXUserID=null}

示例 Java 代码

@Component
public class MyAppCoreRouter extends RouteBuilder {

    /* Other code */

    @Override
    public void configure() {
        from("activemq:queue:taskQueue?concurrentConsumers=" + taskNumberOfConcurrentConsumers)
                .log("***HEADERS IN***: ${headers}")
                .routeId("taskQueueConsumer")
                .threads(taskNumberOfConcurrentConsumers)
                .pollEnrich().simple("aws-s3://myapp-task?amazonS3Client=#amazonS3Client&fileName=${header.filename}&operation=getObject")
                .choice()
                .when(header(S3Constants.KEY).endsWith(".zip"))
                .to("file://" + taskLocalUnCompressedEndpoint + "?fileName=${header.CamelAwsS3ETag}/${header.CamelAwsS3Key}")
                .process(exchange -> {
                    String camelAwsS3ETag = exchange.getIn().getHeader("CamelAwsS3ETag", String.class);
                    String camelAwsS3Key = exchange.getIn().getHeader("CamelAwsS3Key", String.class);
                    File uniqueDir = new File(taskLocalUnCompressedEndpoint, camelAwsS3ETag);
                    File taskZip = new File(uniqueDir, camelAwsS3Key);
                    new ZipFile(taskZip).extractAll(uniqueDir.getAbsolutePath());
                })
                .setHeader("resourceDirectory", simple(taskLocalUnCompressedEndpoint + "/${header.CamelAwsS3ETag}")).setHeader("schedule.time", simple("${date:now}"))
                .removeHeader("CamelAwsS3Headers")
                .log(LoggingLevel.DEBUG, "Processing batch job ${headers}")
                .to("spring-batch:importMyAppRecordJob")
                .endChoice()
                .otherwise()
                .log(LoggingLevel.WARN, "Unexpected file type, filtering file name ${header.CamelAwsS3Key} ")
                .end();

        /* Other code */
    }
}

推荐答案

您使用了错误版本的 Boot、Cloud 和 Sleuth.要使用 Sleuth 3.0.x,您需要使用 Cloud 2020.0.x 和 Boot 2.4.x 或 2.5.x.

You're using wrong versions of Boot, Cloud and Sleuth. To use Sleuth 3.0.x you need to use Cloud 2020.0.x and Boot 2.4.x or 2.5.x.

这篇关于Spring Coud Sleuth 导致 ActiveMQ/JMS 消息头丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆