此内容没有您所选择的语言版本。

Chapter 351. Example


To enable camel-zipkin you need to configure first

ZipkinTracer zipkin = new ZipkinTracer();
// Configure a reporter, which controls how often spans are sent
//   (the dependency is io.zipkin.reporter2:zipkin-sender-okhttp3)
sender = OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
zipkin.setSpanReporter(AsyncReporter.create(sender));
// and then add zipkin to the CamelContext
zipkin.init(camelContext);

The configuration above will trace all incoming and outgoing messages in Camel routes. 

To use ZipkinTracer in XML, all you need to do is to define scribe and zipkin tracer beans. Camel will automatically discover and use them.

  <!-- configure how to reporter spans to a Zipkin collector
          (the dependency is io.zipkin.reporter2:zipkin-reporter-spring-beans) -->
  <bean id="http" class="zipkin2.reporter.beans.AsyncReporterFactoryBean">
    <property name="sender">
      <bean id="sender" class="zipkin2.reporter.beans.OkHttpSenderFactoryBean">
        <property name="endpoint" value="http://localhost:9411/api/v2/spans"/>
      </bean>
    </property>
    <!-- wait up to half a second for any in-flight spans on close -->
    <property name="closeTimeout" value="500"/>
  </bean>

  <!-- setup zipkin tracer -->
  <bean id="zipkinTracer" class="org.apache.camel.zipkin.ZipkinTracer">
    <property name="serviceName" value="dude"/>
    <property name="spanReporter" ref="http"/>
  </bean>

351.1. ServiceName

However, if you want to map Camel endpoints to human friendly logical names, you can add mappings

  • ServiceName *

You can configure a global service name that all events will fallback and use, such as:

zipkin.setServiceName("invoices");

This will use the same service name for all incoming and outgoing zipkin traces. If your application uses different services, you should map them to more finely grained client / server service mappings

351.2. Client and Server Service Mappings

  • ClientServiceMappings
  • ServerServiceMappings

If your application hosts a service that others can call, you can map the Camel route endpoint to a server service mapping. For example, suppose your Camel application has the following route:

from("activemq:queue:inbox")
  .to("http:someserver/somepath");

And you want to make that as a server service, you can add the following mapping:

zipkin.addServerServiceMapping("activemq:queue:inbox", "orders");

Then when a message is consumed from that inbox queue, it becomes a zipkin server event with the service name 'orders'.

Now suppose that the call to http:someserver/somepath is also a service, which you want to map to a client service name, which can be done as:

zipkin.addClientServiceMapping("http:someserver/somepath", "audit");

Then in the same Camel application you have mapped incoming and outgoing endpoints to different zipkin service names.

You can use wildcards in the service mapping. To match all outgoing calls to the same HTTP server you can do:

zipkin.addClientServiceMapping("http:someserver*", "audit");
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部