From 084aa0c83843577190f31188f3a6df476882eb82 Mon Sep 17 00:00:00 2001 From: Pascal Schumacher Date: Fri, 9 Feb 2018 17:45:30 +0100 Subject: [PATCH] CAMEL-12233: spring-boot: add threadNamePattern property --- .../spring/boot/CamelAutoConfiguration.java | 4 ++++ .../boot/CamelConfigurationProperties.java | 20 +++++++++++++++++++ .../boot/CamelAutoConfigurationTest.java | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index 4757ab475900b..ef71ac32545ed 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -227,6 +227,10 @@ static CamelContext doConfigureCamelContext(ApplicationContext applicationContex camelContext.setReloadStrategy(reload); } + if (config.getThreadNamePattern() != null) { + camelContext.getExecutorServiceManager().setThreadNamePattern(config.getThreadNamePattern()); + } + // additional advanced configuration which is not configured using CamelConfigurationProperties afterPropertiesSet(applicationContext, camelContext); diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java index 9882a136670cb..4f3c5a0946e20 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java @@ -449,6 +449,18 @@ public class CamelConfigurationProperties { */ private boolean useMDCLogging; + /** + * Sets the thread name pattern used for creating the full thread name. + *

+ * The default pattern is: Camel (#camelId#) thread ##counter# - #name# + *

+ * Where #camelId# is the name of the {@link org.apache.camel.CamelContext} + *
and #counter# is a unique incrementing counter. + *
and #name# is the regular thread name. + *
You can also use #longName# is the long thread name which can includes endpoint parameters etc. + */ + private String threadNamePattern; + // Getters & setters public String getName() { @@ -948,4 +960,12 @@ public boolean isUseMDCLogging() { public void setUseMDCLogging(boolean useMDCLogging) { this.useMDCLogging = useMDCLogging; } + + public String getThreadNamePattern() { + return threadNamePattern; + } + + public void setThreadNamePattern(String threadNamePattern) { + this.threadNamePattern = threadNamePattern; + } } diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java index 9a64e8c9d76d2..624dfba1351f1 100644 --- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java @@ -50,7 +50,8 @@ "camel.springboot.consumerTemplateCacheSize=100", "camel.springboot.jmxEnabled=true", "camel.springboot.name=customName", - "camel.springboot.typeConversion=true"} + "camel.springboot.typeConversion=true", + "camel.springboot.threadNamePattern=customThreadName #counter#"} ) public class CamelAutoConfigurationTest extends Assert { @@ -171,6 +172,11 @@ public void shouldLoadXmlRoutes() throws InterruptedException { xmlAutoLoadingMock.assertIsSatisfied(); } + @Test + public void shouldChangeThreadNamePattern() { + assertEquals(camelContext.getExecutorServiceManager().getThreadNamePattern(), "customThreadName #counter#"); + } + @Configuration public static class TestConfig { // Constants