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를 사용하려면 설명 및 zipkin 추적기 빈을 정의하는 데 필요한 모든 것이 있습니다. 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 추적에 동일한 서비스 이름이 사용됩니다. 애플리케이션에서 다른 서비스를 사용하는 경우 더 세분화된 클라이언트/서버 서비스 매핑에 매핑해야 합니다.