Updated messaging code

This commit is contained in:
Marcin Grzejszczak
2018-03-12 15:47:08 +01:00
parent 171daaf280
commit bf6546c2ab
5 changed files with 104 additions and 6 deletions

View File

@@ -1125,6 +1125,8 @@ include::../../../../spring-cloud-sleuth-core/src/test/java/org/springframework/
=== Messaging
Features from this section can be disabled by setting the `spring.sleuth.messaging.enabled` property with value equal to `false`.
==== Spring Integration and Spring Cloud Stream
Spring Cloud Sleuth integrates with http://projects.spring.io/spring-integration/[Spring Integration].
@@ -1142,7 +1144,7 @@ Decorating the Spring Integration Executor Channel with `TraceableExecutorServic
We instrument the `RabbitTemplate` so that tracing headers get injected
into the message.
To block this feature, set `spring.sleuth.messaging.enabled` to `false`.
To block this feature, set `spring.sleuth.messaging.rabbit.enabled` to `false`.
==== Spring Kafka
@@ -1150,7 +1152,7 @@ We instrument the Spring Kafka's `ProducerFactory` and `ConsumerFactory`
so that tracing headers get injected into the created Spring Kafka's
`Producer` and `Consumer`.
To block this feature, set `spring.sleuth.messaging.enabled` to `false`.
To block this feature, set `spring.sleuth.messaging.kafka.enabled` to `false`.
=== Zuul

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.messaging;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
* @author Marcin Grzejszczak
* @since 2.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@ConditionalOnProperty(value = "spring.sleuth.messaging.enabled", matchIfMissing = true)
@interface OnMessagingEnabled {
}

View File

@@ -60,6 +60,38 @@ public class SleuthMessagingProperties {
public static class Messaging {
private boolean enabled;
private Rabbit rabbit = new Rabbit();
private Kafka kafka = new Kafka();
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Rabbit getRabbit() {
return this.rabbit;
}
public void setRabbit(Rabbit rabbit) {
this.rabbit = rabbit;
}
public Kafka getKafka() {
return this.kafka;
}
public void setKafka(Kafka kafka) {
this.kafka = kafka;
}
}
public static class Rabbit {
private boolean enabled;
private String remoteServiceName = "rabbitmq";
public boolean isEnabled() {
@@ -78,4 +110,26 @@ public class SleuthMessagingProperties {
this.remoteServiceName = remoteServiceName;
}
}
public static class Kafka {
private boolean enabled;
private String remoteServiceName = "kafka";
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRemoteServiceName() {
return this.remoteServiceName;
}
public void setRemoteServiceName(String remoteServiceName) {
this.remoteServiceName = remoteServiceName;
}
}
}

View File

@@ -52,11 +52,12 @@ import org.springframework.kafka.core.ProducerFactory;
@Configuration
@ConditionalOnBean(Tracing.class)
@AutoConfigureAfter({ TraceAutoConfiguration.class })
@ConditionalOnProperty(value = "spring.sleuth.messaging.enabled", matchIfMissing = true)
@OnMessagingEnabled
@EnableConfigurationProperties(SleuthMessagingProperties.class)
public class TraceMessagingAutoConfiguration {
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.messaging.rabbit.enabled", matchIfMissing = true)
@ConditionalOnClass(RabbitTemplate.class)
protected static class SleuthRabbitConfiguration {
@Bean
@@ -64,7 +65,7 @@ public class TraceMessagingAutoConfiguration {
SpringRabbitTracing springRabbitTracing(Tracing tracing,
SleuthMessagingProperties properties) {
return SpringRabbitTracing.newBuilder(tracing)
.remoteServiceName(properties.getMessaging().getRemoteServiceName())
.remoteServiceName(properties.getMessaging().getRabbit().getRemoteServiceName())
.build();
}
@@ -77,13 +78,17 @@ public class TraceMessagingAutoConfiguration {
}
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.messaging.kafka.enabled", matchIfMissing = true)
@ConditionalOnClass(ProducerFactory.class)
protected static class SleuthKafkaConfiguration {
@Bean
@ConditionalOnMissingBean
KafkaTracing kafkaTracing(Tracing tracing) {
return KafkaTracing.create(tracing);
KafkaTracing kafkaTracing(Tracing tracing, SleuthMessagingProperties properties) {
return KafkaTracing
.newBuilder(tracing)
.remoteServiceName(properties.getMessaging().getKafka().getRemoteServiceName())
.build();
}
@Bean

View File

@@ -41,6 +41,7 @@ import org.springframework.integration.config.GlobalChannelInterceptor;
@ConditionalOnClass(GlobalChannelInterceptor.class)
@ConditionalOnBean(Tracing.class)
@AutoConfigureAfter({ TraceAutoConfiguration.class })
@OnMessagingEnabled
@ConditionalOnProperty(value = "spring.sleuth.integration.enabled", matchIfMissing = true)
@EnableConfigurationProperties(SleuthMessagingProperties.class)
public class TraceSpringIntegrationAutoConfiguration {