383.10. 示例
要启用 camel-zipkin,您需要首先配置
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);
上述配置将跟踪 Camel 路由中的所有传入和传出消息。
要在 XML 中使用 ZipkinTracer,所有您需要做的就是定义 scribe 和 zipkin tracer Bean。Camel 将自动发现并使用它们。
<!-- 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>
383.10.1. ServiceName
但是,如果要将 Camel 端点映射到人类友好逻辑名称,您可以添加映射
- ServiceName *
您可以配置所有事件将回退和使用的全局服务名称,例如:
zipkin.setServiceName("invoices");
这将对所有传入和传出的 zipkin trace 使用相同的服务名称。如果您的应用程序使用不同的服务,您应该将它们映射到更精细的客户端/服务器服务映射