Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 871DE200C3D for ; Tue, 14 Mar 2017 13:17:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 85A15160B7E; Tue, 14 Mar 2017 12:17:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A91AB160B7C for ; Tue, 14 Mar 2017 13:17:30 +0100 (CET) Received: (qmail 43985 invoked by uid 500); 14 Mar 2017 12:17:29 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 43940 invoked by uid 99); 14 Mar 2017 12:17:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Mar 2017 12:17:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 51693DFDC8; Tue, 14 Mar 2017 12:17:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zregvart@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-11008: Consumer/Producer templates are no... Date: Tue, 14 Mar 2017 12:17:28 +0000 (UTC) archived-at: Tue, 14 Mar 2017 12:17:31 -0000 Repository: camel Updated Branches: refs/heads/camel-2.17.x c82fd3bae -> 562794a7a 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/562794a7 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/562794a7 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/562794a7 Branch: refs/heads/camel-2.17.x Commit: 562794a7a34843fd169edf19a1daf134c8418684 Parents: c82fd3b Author: Zoran Regvart Authored: Mon Mar 13 23:42:12 2017 +0100 Committer: Zoran Regvart Committed: Tue Mar 14 13:16:44 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/562794a7/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 1385968..d8c3d36 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 @@ -100,8 +100,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; } /** @@ -111,8 +113,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/562794a7/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