微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何保留父级跨度以与 Apache Camel 进行聚合?

如何解决如何保留父级跨度以与 Apache Camel 进行聚合?

我有一个带有 Aggregate EIP 的 Apache Camel 应用程序,它使用 JdbcAggregationRepository 来持久化交换。我还使用带有 Jaeger 的 OpenTracing component 来跟踪我的应用程序。但是聚合后下一个span的父span是错误的。

Jaeger 界面

enter image description here

具有直接 output 的路由跨度应该是具有直接 aggregate 的路由跨度之一的子级。

Spring Boot 应用

@SpringBootApplication
@CamelOpenTracing
public class TestApplication {

  @Bean
  public EndpointRouteBuilder routeBuilder(AggregationRepository testAggregationRepository,AggregationStrategy testAggregationStrategy) {
    return new EndpointRouteBuilder() {
      public void configure() throws Exception {
        from(file("d:/tmp/camel/")).to(file("d:/tmp/backup")).unmarshal().json().multicast().to(direct("aggregate"),direct("aggregate"));
 
        from(direct("aggregate")).aggregate(header("CamelFileName"),testAggregationStrategy).aggregationRepository(testAggregationRepository).completionSize(2).to(direct("output"));

        from(direct("output")).stop();
      }
    };
  }

  @Bean
  public AggregationRepository testAggregationRepository(final PlatformTransactionManager platformTransactionManager,final DataSource dataSource) {
    final JdbcAggregationRepository repository = new JdbcAggregationRepository();
    repository.setRepositoryName("test_aggregation");
    repository.setTransactionManager(platformTransactionManager);
    repository.setDataSource(dataSource);
    return repository;
  }

  @Bean
  public AggregationStrategy testAggregationStrategy() {
    return new AggregationStrategy() {
      public Exchange aggregate(Exchange oldExchange,Exchange newExchange) {
        return oldExchange == null ? newExchange : oldExchange;
      }
    };
  }

  public static void main(String[] args) {
    SpringApplication.run(TestApplication.class,args);
  }
}

日志

INFO 5128 --- [//d:/tmp/camel/] i.j.internal.reporters.LoggingReporter   : Span reported: 6236476473ecdbfb:ec779aef59f2cf8e:6236476473ecdbfb:1 - file
INFO 5128 --- [//d:/tmp/camel/] i.j.internal.reporters.LoggingReporter   : Span reported: 6236476473ecdbfb:53319f61d8a8c361:6236476473ecdbfb:1 - aggregate
INFO 5128 --- [//d:/tmp/camel/] i.j.internal.reporters.LoggingReporter   : Span reported: 6236476473ecdbfb:6b9ae71954dff9be:ec779aef59f2cf8e:1 - output
INFO 5128 --- [//d:/tmp/camel/] i.j.internal.reporters.LoggingReporter   : Span reported: 6236476473ecdbfb:909adb98d6a87cb6:6236476473ecdbfb:1 - aggregate
INFO 5128 --- [//d:/tmp/camel/] i.j.internal.reporters.LoggingReporter   : Span reported: 6236476473ecdbfb:6236476473ecdbfb:0:1 - file

另见Trace/Span Identity

研究

如果我从路由中删除 .to(file("d:/tmp/backup")),我也会丢失跟踪 ID。具有直接 output 的路由的跨度使用新的跟踪 ID。因此,它与其他跨度分开。

问题

如何在聚合后保留父跨度?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。