You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/07/29 10:03:55 UTC

[1/2] camel git commit: CAMEL-11613: camel-spring-boot - Add auto configuration for FluentProducerTemplate

Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x 2fa96127f -> 468def270
  refs/heads/master 9387b8198 -> 05a0d5168


CAMEL-11613: camel-spring-boot - Add auto configuration for FluentProducerTemplate


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/05a0d516
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/05a0d516
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/05a0d516

Branch: refs/heads/master
Commit: 05a0d51685e5c2f62c05bfa06b03806d73717573
Parents: 9387b81
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 29 11:58:06 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 29 11:59:41 2017 +0200

----------------------------------------------------------------------
 .../spring/boot/CamelAutoConfiguration.java     | 22 +++++++++++++++++++-
 .../CamelSpringBootTemplateShutdownTest.java    |  8 +++++++
 .../boot/mockendpoints/MockEndpointsTest.java   |  6 +++---
 3 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/05a0d516/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 330b8d2..7a1307fd 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
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.TypeConverters;
 import org.apache.camel.component.properties.PropertiesComponent;
@@ -46,7 +47,6 @@ import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.ReloadStrategy;
-import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RouteController;
 import org.apache.camel.spi.RoutePolicyFactory;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
@@ -226,6 +226,26 @@ public class CamelAutoConfiguration {
     }
 
     /**
+     * Default fluent producer template for the bootstrapped Camel context.
+     * Create the bean lazy as it should only be created if its in-use.
+     */
+    // We explicitly declare the destroyMethod to be "" as the Spring @Bean
+    // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise
+    // and in that case Service::close (FluentProducerTemplate implements Service)
+    // would be used for bean destruction. And we want Camel to handle the
+    // lifecycle.
+    @Bean(destroyMethod = "")
+    @ConditionalOnMissingBean(FluentProducerTemplate.class)
+    @Lazy
+    FluentProducerTemplate fluentProducerTemplate(CamelContext camelContext,
+                                                 CamelConfigurationProperties config) throws Exception {
+        final FluentProducerTemplate fluentProducerTemplate = camelContext.createFluentProducerTemplate(config.getProducerTemplateCacheSize());
+        // we add this fluentProducerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop)
+        camelContext.addService(fluentProducerTemplate);
+        return fluentProducerTemplate;
+    }
+
+    /**
      * Default producer template for the bootstrapped Camel context.
      * Create the bean lazy as it should only be created if its in-use.
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/05a0d516/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
index d1cacaf..2a1d88a 100644
--- 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
@@ -18,6 +18,7 @@ package org.apache.camel.spring.boot;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.support.ServiceSupport;
 import org.junit.Before;
@@ -40,30 +41,36 @@ public class CamelSpringBootTemplateShutdownTest {
 
     ProducerTemplate producerTemplate;
 
+    FluentProducerTemplate fluentProducerTemplate;
+
     @Before
     public void setupApplicationContext() {
         applicationContext = new AnnotationConfigApplicationContext(CamelAutoConfiguration.class);
         camelContext = applicationContext.getBean(CamelContext.class);
         consumerTemplate = applicationContext.getBean(ConsumerTemplate.class);
         producerTemplate = applicationContext.getBean(ProducerTemplate.class);
+        fluentProducerTemplate = applicationContext.getBean(FluentProducerTemplate.class);
     }
 
     @Test
     public void shouldStopTemplatesWithCamelShutdown() throws Exception {
         assertTrue(((ServiceSupport) consumerTemplate).isStarted());
         assertTrue(((ServiceSupport) producerTemplate).isStarted());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStarted());
 
         camelContext.stop();
 
         assertTrue(((ServiceSupport) camelContext).isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
     }
 
     @Test
     public void shouldStopTemplatesWithApplicationContextShutdown() throws Exception {
         assertTrue(((ServiceSupport) consumerTemplate).isStarted());
         assertTrue(((ServiceSupport) producerTemplate).isStarted());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStarted());
 
         applicationContext.close();
 
@@ -71,6 +78,7 @@ public class CamelSpringBootTemplateShutdownTest {
         assertTrue(((ServiceSupport) camelContext).isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/05a0d516/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
index 80b6c9d..e721dfa 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
@@ -17,7 +17,7 @@
 package org.apache.camel.spring.boot.mockendpoints;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.ProducerTemplate;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.spring.CamelSpringBootRunner;
 import org.apache.camel.test.spring.MockEndpoints;
@@ -34,7 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 public class MockEndpointsTest {
 
     @Autowired
-    ProducerTemplate producerTemplate;
+    FluentProducerTemplate producerTemplate;
 
     @Autowired
     CamelContext camelContext;
@@ -48,7 +48,7 @@ public class MockEndpointsTest {
         mock.expectedBodiesReceived(msg);
 
         // When
-        producerTemplate.sendBody("direct:start", msg);
+        producerTemplate.withBody(msg).to("direct:start").send();
 
         // Then
         mock.assertIsSatisfied();


[2/2] camel git commit: CAMEL-11613: camel-spring-boot - Add auto configuration for FluentProducerTemplate

Posted by da...@apache.org.
CAMEL-11613: camel-spring-boot - Add auto configuration for FluentProducerTemplate


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/468def27
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/468def27
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/468def27

Branch: refs/heads/camel-2.19.x
Commit: 468def2702ef45a2a888657a7792bca86872ec6c
Parents: 2fa9612
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 29 11:58:06 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 29 12:00:56 2017 +0200

----------------------------------------------------------------------
 .../spring/boot/CamelAutoConfiguration.java     | 21 +++++++++++++++++++-
 .../CamelSpringBootTemplateShutdownTest.java    |  8 ++++++++
 .../boot/mockendpoints/MockEndpointsTest.java   |  6 +++---
 3 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/468def27/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 96e0d52..37b58e5 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
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.TypeConverters;
 import org.apache.camel.component.properties.PropertiesComponent;
@@ -45,7 +46,6 @@ import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.ReloadStrategy;
-import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RoutePolicyFactory;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.ShutdownStrategy;
@@ -219,6 +219,25 @@ public class CamelAutoConfiguration {
     }
 
     /**
+     * Default fluent producer template for the bootstrapped Camel context.
+     * Create the bean lazy as it should only be created if its in-use.
+     */
+    // We explicitly declare the destroyMethod to be "" as the Spring @Bean
+    // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise
+    // and in that case Service::close (FluentProducerTemplate implements Service)
+    // would be used for bean destruction. And we want Camel to handle the
+    // lifecycle.
+    @Bean(destroyMethod = "")
+    @ConditionalOnMissingBean(FluentProducerTemplate.class)
+    FluentProducerTemplate fluentProducerTemplate(CamelContext camelContext,
+                                                 CamelConfigurationProperties config) throws Exception {
+        final FluentProducerTemplate fluentProducerTemplate = camelContext.createFluentProducerTemplate(config.getProducerTemplateCacheSize());
+        // we add this fluentProducerTemplate as a Service to CamelContext so that it performs proper lifecycle (start and stop)
+        camelContext.addService(fluentProducerTemplate);
+        return fluentProducerTemplate;
+    }
+
+    /**
      * Default producer template for the bootstrapped Camel context.
      */
     @Bean(initMethod = "", destroyMethod = "")

http://git-wip-us.apache.org/repos/asf/camel/blob/468def27/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
index d1cacaf..2a1d88a 100644
--- 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
@@ -18,6 +18,7 @@ package org.apache.camel.spring.boot;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.support.ServiceSupport;
 import org.junit.Before;
@@ -40,30 +41,36 @@ public class CamelSpringBootTemplateShutdownTest {
 
     ProducerTemplate producerTemplate;
 
+    FluentProducerTemplate fluentProducerTemplate;
+
     @Before
     public void setupApplicationContext() {
         applicationContext = new AnnotationConfigApplicationContext(CamelAutoConfiguration.class);
         camelContext = applicationContext.getBean(CamelContext.class);
         consumerTemplate = applicationContext.getBean(ConsumerTemplate.class);
         producerTemplate = applicationContext.getBean(ProducerTemplate.class);
+        fluentProducerTemplate = applicationContext.getBean(FluentProducerTemplate.class);
     }
 
     @Test
     public void shouldStopTemplatesWithCamelShutdown() throws Exception {
         assertTrue(((ServiceSupport) consumerTemplate).isStarted());
         assertTrue(((ServiceSupport) producerTemplate).isStarted());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStarted());
 
         camelContext.stop();
 
         assertTrue(((ServiceSupport) camelContext).isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
     }
 
     @Test
     public void shouldStopTemplatesWithApplicationContextShutdown() throws Exception {
         assertTrue(((ServiceSupport) consumerTemplate).isStarted());
         assertTrue(((ServiceSupport) producerTemplate).isStarted());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStarted());
 
         applicationContext.close();
 
@@ -71,6 +78,7 @@ public class CamelSpringBootTemplateShutdownTest {
         assertTrue(((ServiceSupport) camelContext).isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
+        assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/468def27/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
index 80b6c9d..e721dfa 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java
@@ -17,7 +17,7 @@
 package org.apache.camel.spring.boot.mockendpoints;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.ProducerTemplate;
+import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.spring.CamelSpringBootRunner;
 import org.apache.camel.test.spring.MockEndpoints;
@@ -34,7 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 public class MockEndpointsTest {
 
     @Autowired
-    ProducerTemplate producerTemplate;
+    FluentProducerTemplate producerTemplate;
 
     @Autowired
     CamelContext camelContext;
@@ -48,7 +48,7 @@ public class MockEndpointsTest {
         mock.expectedBodiesReceived(msg);
 
         // When
-        producerTemplate.sendBody("direct:start", msg);
+        producerTemplate.withBody(msg).to("direct:start").send();
 
         // Then
         mock.assertIsSatisfied();