In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use OpenTracing and Jaeger to track Pulsar messages, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
OpenTracing (https://opentracing.io/) is an open distributed tracking standard for applications and OSS (Open-Source Software) packages. Many tracking back-end services support OpenTracing API, such as Jaeger, Zipkin, and SkyWalking.
Preparatory work
Before you begin, you need to install JDK 8, Maven 3, and Pulsar (cluster mode or stand-alone mode). If you don't already have Pulsar installed, check the link below and follow the prompts to install it.
Http://pulsar.apache.org/docs/en/standalone/
Step 1: start the Jaeger backend
1. Start the Jaeger backend in Docker.
Docker run-d-p 6831:6831/udp-p 16686purl 16686 jaegertracing/all-in-one:latest
After you successfully start Jaeger, you can open the Jaeger UI website.
? If you don't have a Jaeger Docker environment, you can:
Download binaries
Https://www.jaegertracing.io/download/
Build from source code
Https://www.jaegertracing.io/docs/1.17/getting-started/#from-source
two。 Visit `http://localhost:16686` and open the Jeager UI website without entering a user name or password.
Step 2: add maven dependencies
This example uses Open Tracing Pulsar Client.
Https://hub.streamnative.io/monitoring/opentracing-pulsar-client/0.1.0
It is an integration of Pulsar Client and OpenTracing API (based on Pulsar Client Interceptors) for tracking Pulsar messages. OpenTracing Pulsar Client is developed by StreamNative and is a monitoring tool in StreamNatvie Hub (https://hub.streamnative.io/)).
Add Jaeger client dependency to connect to the Jaeger backend.
Org.apache.pulsar pulsar-client 2.5.1
Io.streamnative opentracing-pulsar-client 0.1.0
Io.jaegertracing jaeger-client 1.2.0
Step 3: use OpenTracing Pulsar Client
For ease of understanding, this example has 2 Job and 2 topic. Job-1 sends messages to topic-A, and Job-2 consumes messages from topc-A. When Job 2 receives a message from topic-A, Job 2 sends a message to topic-B, and then Job-3 consumes the message from topic-B. Therefore, there are 2 topic, 2 producer, and 2 consumer in this case.
To complete the tasks in the above work scenario, you need to start three applications.
Job-1: publish messages to topic-A
Job-2: consume messages in topic-An and publish messages to topic-B
Job-3: consuming messages in topic-B
? Job-1
The following example is to publish a message to topic-A.
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv (). WithType ("const"). WithParam (1); Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv (). WithLogSpans (true); Configuration configuration = new Configuration ("Job-1") .withSampler (samplerConfig) .withReporter (reporterConfig); Tracer tracer = configuration.getTracer (); GlobalTracer.registerIfAbsent (tracer); PulsarClient client = PulsarClient.builder () .serviceUrl ("pulsar://localhost:6650") .build () Producer producerA = client.newProducer (Schema.STRING) .topic ("topic-A") .intercept (new TracingProducerInterceptor ()) .create (); for (int I = 0; I < 10; iTunes +) {producerA.newMessage () .value (String.format ("[% d] Hello", I)) .send ();}?? Job-2
The following example consumes a message from topic-An and publishes it to topic-B.
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv (). WithType ("const"). WithParam (1); Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv (). WithLogSpans (true); Configuration configuration = new Configuration ("Job-2") .withSampler (samplerConfig) .withReporter (reporterConfig); Tracer tracer = configuration.getTracer (); GlobalTracer.registerIfAbsent (tracer); PulsarClient client = PulsarClient.builder () .serviceUrl ("pulsar://localhost:6650") .build () Consumer consumer = client.newConsumer (Schema.STRING) .topic ("topic-A") .subscriptionName ("open-tracing") .subscriptionType (SubscriptionType.Shared) .intercept (new TracingConsumerInterceptor ()) .subsc ribe (); Producer producerB = client.newProducer (Schema.STRING) .topic ("topic-B") .intercept (new TracingProducerInterceptor ()) .create (); while (true) {Message received = consumer.receive () SpanContext context = TracingPulsarUtils.extractSpanContext (received, tracer); TypedMessageBuilder messageBuilder = producerB.newMessage (); messageBuilder.value (received.getValue () + "Pulsar and OpenTracing!"); / / Inject parent span context tracer.inject (context, Format.Builtin.TEXT_MAP, new TypeMessageBuilderInjectAdapter (messageBuilder)); messageBuilder.send (); consumer.acknowledge (received);}
? Job-3
The following example is consuming messages from topic-B.
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv (). WithType ("const"). WithParam (1); Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv (). WithLogSpans (true); Configuration configuration = new Configuration ("Job-3") .withSampler (samplerConfig) .withReporter (reporterConfig); Tracer tracer = configuration.getTracer (); GlobalTracer.registerIfAbsent (tracer); PulsarClient client = PulsarClient.builder () .serviceUrl ("pulsar://localhost:6650") .build () Consumer consumer = client.newConsumer (Schema.STRING) .topic ("topic-B") .subscriptionName ("open-tracing") .subscriptionType (SubscriptionType.Shared) .intercept (new TracingConsumerInterceptor ()) .subsc ribe (); while (true) {Message received = consumer.receive (); System.out.println (received.getValue ()); consumer.acknowledge (received);}
Now you can run Job-3, Job-2, and Job-1, respectively. The log received by Job-3 appears in the console, as follows:
[0] Hello Pulsar and OpenTracing! [1] Hello Pulsar and OpenTracing!... [9] Hello Pulsar and OpenTracing!
Now you can turn on Jaeger UI again and ten message tracking links will appear on the page.
Click the task name to view the details of the message tracking link.
You can easily tell whether this message is published by producer or consumer from the span name. The span name is in the format of `To__ `and `From____`.
The above is how to use OpenTracing and Jaeger to track Pulsar messages. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.