changeset 18:8504317b9a09

Erweiterung um Sleuth, manuelle Konfiguration von Spring
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 17 Sep 2020 09:03:11 +0200
parents a9675808f1dd
children fe6a57f7a2cf
files spring-jms-playground/pom.xml spring-jms-playground/src/main/java/de/comline/jms/application/Application.java spring-jms-playground/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/ExposedSleuthJmsConfiguration.java spring-jms-playground/src/main/resources/application.properties spring-jms-playground/src/main/resources/logback-spring.xml
diffstat 5 files changed, 62 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/spring-jms-playground/pom.xml	Thu Sep 10 11:18:13 2020 +0200
+++ b/spring-jms-playground/pom.xml	Thu Sep 17 09:03:11 2020 +0200
@@ -2,12 +2,6 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.springframework.boot</groupId>
-		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>2.1.16.RELEASE</version>
-		<relativePath/>
-	</parent>
 	<groupId>de.comline</groupId>
 	<artifactId>spring-jms-playground</artifactId>
 	<version>0.0.1-SNAPSHOT</version>
@@ -37,11 +31,34 @@
 		</plugins>
 	</build>
 
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-starter-parent</artifactId>
+				<version>2.1.16.RELEASE</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+			<dependency>
+				<groupId>org.springframework.cloud</groupId>
+				<artifactId>spring-cloud-dependencies</artifactId>
+				<version>Greenwich.SR6</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
+
 	<dependencies>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-activemq</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-sleuth</artifactId>
+		</dependency>
         
 		<dependency>
 			<groupId>org.junit.jupiter</groupId>
--- a/spring-jms-playground/src/main/java/de/comline/jms/application/Application.java	Thu Sep 10 11:18:13 2020 +0200
+++ b/spring-jms-playground/src/main/java/de/comline/jms/application/Application.java	Thu Sep 17 09:03:11 2020 +0200
@@ -8,6 +8,11 @@
 import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
 import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
 import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
+import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
+import org.springframework.cloud.sleuth.instrument.messaging.ExposedSleuthJmsConfiguration;
+import org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration;
+import org.springframework.cloud.sleuth.instrument.messaging.TraceSpringIntegrationAutoConfiguration;
+import org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
@@ -20,15 +25,21 @@
 @Import(AppConfig.class)
 public class Application {
 	private static final Logger LOG = LoggerFactory.getLogger(Application.class);
-	
+
 	public static final String AMQ_FACTORY_BEAN = "amqFactory";
 
 	public static void main(String[] args) {
 		SpringApplication.run(Application.class, args);
 	}
 
+	// @formatter:off
+//	@EnableAutoConfiguration
+//	@Import(QueueReceiver.class)
 	@Configuration
-	@Import({ ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class, QueueReceiver.class })
+	@Import({ SleuthLogAutoConfiguration.class, TraceAutoConfiguration.class, TraceMessagingAutoConfiguration.class, ExposedSleuthJmsConfiguration.class, TraceSpringIntegrationAutoConfiguration.class,
+		ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class,
+		QueueReceiver.class })
+	// @formatter:on
 	public static class AppConfig {
 		@Bean(name = AMQ_FACTORY_BEAN)
 		public JmsListenerContainerFactory<?> configureJmsListenerFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-jms-playground/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/ExposedSleuthJmsConfiguration.java	Thu Sep 17 09:03:11 2020 +0200
@@ -0,0 +1,13 @@
+package org.springframework.cloud.sleuth.instrument.messaging;
+
+import org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration.SleuthJmsConfiguration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * This subclass is requierd to expose {@link SleuthJmsConfiguration} for
+ * {@link Import}ing in a static configuration. It should not be required as
+ * {@link SleuthJmsConfiguration} should be public.
+ */
+public class ExposedSleuthJmsConfiguration extends TraceMessagingAutoConfiguration.SleuthJmsConfiguration {
+	// just a hack for exposing the config to our app
+}
--- a/spring-jms-playground/src/main/resources/application.properties	Thu Sep 10 11:18:13 2020 +0200
+++ b/spring-jms-playground/src/main/resources/application.properties	Thu Sep 17 09:03:11 2020 +0200
@@ -1,3 +1,10 @@
+logging.pattern.console = %d{HH:mm:ss.SSS} %-5p [%10.10t] [${spring.zipkin.service.name:${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] %c{1} : %m%n
+
 #spring.activemq.user=admin
 #spring.activemq.password=admin
 spring.activemq.broker-url=tcp://localhost:61616
+
+spring.application.name = jmstest
+
+spring.sleuth.messaging.enabled = true
+spring.sleuth.messaging.jms.enabled = true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-jms-playground/src/main/resources/logback-spring.xml	Thu Sep 17 09:03:11 2020 +0200
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false">
+    <include resource="org/springframework/boot/logging/logback/base.xml"/>
+
+<!--     <logger name="org.springframework.jms" level="DEBUG"/> -->
+</configuration>
\ No newline at end of file