You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2017/03/14 11:47:03 UTC
camel git commit: CAMEL-11008: Consumer/Producer templates are no...
Repository: camel
Updated Branches:
refs/heads/master 4e1cfa87c -> 25d1d418e
CAMEL-11008: Consumer/Producer templates are no...
...t stopped when auto-configured in Spring Boot
Adds `addService` for Consumer/Producer templates when configured from
Spring Boot this ensures that these are stopped on CamelContext shutdown
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/25d1d418
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/25d1d418
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/25d1d418
Branch: refs/heads/master
Commit: 25d1d418eba7e510350d95b19a2f50c256f18d38
Parents: 4e1cfa8
Author: Zoran Regvart <zr...@apache.org>
Authored: Mon Mar 13 23:42:12 2017 +0100
Committer: Zoran Regvart <zr...@apache.org>
Committed: Tue Mar 14 12:46:21 2017 +0100
----------------------------------------------------------------------
.../spring/boot/CamelAutoConfiguration.java | 12 ++--
.../CamelSpringBootTemplateShutdownTest.java | 74 ++++++++++++++++++++
2 files changed, 82 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/25d1d418/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
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 4870a65..8d0bf49 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
@@ -222,8 +222,10 @@ public class CamelAutoConfiguration {
// Camel handles the lifecycle of this bean
@ConditionalOnMissingBean(ProducerTemplate.class)
ProducerTemplate producerTemplate(CamelContext camelContext,
- CamelConfigurationProperties config) {
- return camelContext.createProducerTemplate(config.getProducerTemplateCacheSize());
+ CamelConfigurationProperties config) throws Exception {
+ final ProducerTemplate producerTemplate = camelContext.createProducerTemplate(config.getProducerTemplateCacheSize());
+ camelContext.addService(producerTemplate);
+ return producerTemplate;
}
/**
@@ -233,8 +235,10 @@ public class CamelAutoConfiguration {
// Camel handles the lifecycle of this bean
@ConditionalOnMissingBean(ConsumerTemplate.class)
ConsumerTemplate consumerTemplate(CamelContext camelContext,
- CamelConfigurationProperties config) {
- return camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize());
+ CamelConfigurationProperties config) throws Exception {
+ final ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize());
+ camelContext.addService(consumerTemplate);
+ return consumerTemplate;
}
// SpringCamelContext integration
http://git-wip-us.apache.org/repos/asf/camel/blob/25d1d418/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
new file mode 100644
index 0000000..0b7b6e0
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.support.ServiceSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CamelSpringBootTemplateShutdownTest {
+
+ CamelContext camelContext;
+
+ AbstractApplicationContext applicationContext;
+
+ ConsumerTemplate consumerTemplate;
+
+ ProducerTemplate producerTemplate;
+
+ @Before
+ public void setupApplicationContext() {
+ applicationContext = new AnnotationConfigApplicationContext(CamelAutoConfiguration.class);
+ camelContext = applicationContext.getBean(CamelContext.class);
+ consumerTemplate = applicationContext.getBean(ConsumerTemplate.class);
+ producerTemplate = applicationContext.getBean(ProducerTemplate.class);
+ }
+
+ @Test
+ public void shouldStopTemplatesWithCamelShutdown() throws Exception {
+ assertTrue(((ServiceSupport) consumerTemplate).isStarted());
+ assertTrue(((ServiceSupport) producerTemplate).isStarted());
+
+ camelContext.stop();
+
+ assertTrue(((ServiceSupport) camelContext).isStopped());
+ assertTrue(((ServiceSupport) consumerTemplate).isStopped());
+ assertTrue(((ServiceSupport) producerTemplate).isStopped());
+ }
+
+ @Test
+ public void shouldStopTemplatesWithApplicationContextShutdown() throws Exception {
+ assertTrue(((ServiceSupport) consumerTemplate).isStarted());
+ assertTrue(((ServiceSupport) producerTemplate).isStarted());
+
+ applicationContext.close();
+
+ assertFalse(applicationContext.isActive());
+ assertTrue(((ServiceSupport) camelContext).isStopped());
+ assertTrue(((ServiceSupport) consumerTemplate).isStopped());
+ assertTrue(((ServiceSupport) producerTemplate).isStopped());
+ }
+
+}
\ No newline at end of file