本文整理汇总了Java中io.opentracing.contrib.kafka.TracingKafkaConsumer类的典型用法代码示例。如果您正苦于以下问题:Java TracingKafkaConsumer类的具体用法?Java TracingKafkaConsumer怎么用?Java TracingKafkaConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TracingKafkaConsumer类属于io.opentracing.contrib.kafka包,在下文中一共展示了TracingKafkaConsumer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.opentracing.contrib.kafka.TracingKafkaConsumer; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) throws Exception {
// INSTRUMENTATION
// Metrics Instrumentation
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
// Tracing Instrumentation
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final HttpHost httpHost = new HttpHost("tweets-elasticsearch", 9200);
final RestClientBuilder restClientBuilder =
RestClient.builder(httpHost).setHttpClientConfigCallback(new TracingHttpClientConfigCallback(metricsTracer));
final RestClient restClient = restClientBuilder.build();
final ElasticsearchTweetRepository elasticsearchRepository = new ElasticsearchTweetRepository(restClient);
final Properties consumerConfigs = new Properties();
consumerConfigs.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "tweets-kafka:9092");
consumerConfigs.put(ConsumerConfig.GROUP_ID_CONFIG, getName());
consumerConfigs.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
consumerConfigs.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
final KafkaConsumer<Long, String> kafkaConsumer = new KafkaConsumer<>(consumerConfigs, new LongDeserializer(), new StringDeserializer());
final TracingKafkaConsumer<Long, String> tracingKafkaConsumer = new TracingKafkaConsumer<>(kafkaConsumer, metricsTracer);
final Runnable kafkaTweetEventConsumer = new KafkaTweetEventConsumer(tracingKafkaConsumer, elasticsearchRepository);
final ExecutorService executorService = environment.lifecycle().executorService("kafka-consumer").build();
executorService.submit(kafkaTweetEventConsumer);
}
示例2: getConsumer
import io.opentracing.contrib.kafka.TracingKafkaConsumer; //导入依赖的package包/类
@Override
public Consumer<byte[], byte[]> getConsumer(Map<String, Object> config) {
return new TracingKafkaConsumer<>(
new KafkaConsumer<>(config, new ByteArrayDeserializer(), new ByteArrayDeserializer()),
tracer);
}
示例3: getRestoreConsumer
import io.opentracing.contrib.kafka.TracingKafkaConsumer; //导入依赖的package包/类
@Override
public Consumer<byte[], byte[]> getRestoreConsumer(Map<String, Object> config) {
return new TracingKafkaConsumer<>(
new KafkaConsumer<>(config, new ByteArrayDeserializer(), new ByteArrayDeserializer()),
tracer);
}
示例4: createConsumer
import io.opentracing.contrib.kafka.TracingKafkaConsumer; //导入依赖的package包/类
@Override
public Consumer<K, V> createConsumer() {
return new TracingKafkaConsumer<>(consumerFactory.createConsumer(), tracer);
}