Updated messaging code
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user