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 2020/03/02 08:15:47 UTC

[camel-spring-boot] 02/02: CAMEL-14568 Fixed reactive streams

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit edd538bfbb802c94582c49f756c94989bd0303e3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 2 09:15:14 2020 +0100

    CAMEL-14568 Fixed reactive streams
---
 .../catalog/components/reactive-streams.json       |  5 ++-
 .../src/main/docs/reactive-streams-starter.adoc    |  7 ++-
 .../ReactiveStreamsComponentConfiguration.java     | 52 +++++++++++++++++++---
 .../ReactiveStreamsServiceAutoConfiguration.java   | 21 +++++----
 .../test/ReactiveStreamsAutoConfigurationTest.java |  8 ++--
 5 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/reactive-streams.json b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/reactive-streams.json
index 7c09a25..3d80821 100644
--- a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/reactive-streams.json
+++ b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/reactive-streams.json
@@ -19,11 +19,14 @@
     "version": "3.2.0-SNAPSHOT"
   },
   "componentProperties": {
+    "threadPoolMaxSize": { "kind": "property", "displayName": "Thread Pool Max Size", "group": "common", "label": "common", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "secret": false, "defaultValue": "10", "description": "The maximum number of threads used by the reactive streams internal engine." },
+    "threadPoolMinSize": { "kind": "property", "displayName": "Thread Pool Min Size", "group": "common", "label": "common", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "secret": false, "description": "The minimum number of threads used by the reactive streams internal engine." },
+    "threadPoolName": { "kind": "property", "displayName": "Thread Pool Name", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "defaultValue": "CamelReactiveStreamsWorker", "description": "The name of the thread pool used by the reactive streams internal engine." },
     "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by [...]
     "backpressureStrategy": { "kind": "property", "displayName": "Backpressure Strategy", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.reactive.streams.ReactiveStreamsBackpressureStrategy", "enum": [ "BUFFER", "OLDEST", "LATEST" ], "deprecated": false, "secret": false, "defaultValue": "BUFFER", "description": "The backpressure strategy to use when pushing events to a slow subscriber." },
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...]
     "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
-    "internalEngineConfiguration": { "kind": "property", "displayName": "Internal Engine Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration", "deprecated": false, "secret": false, "description": "Configures the internal engine for Reactive Streams." },
+    "reactiveStreamsEngineConfiguration": { "kind": "property", "displayName": "Reactive Streams Engine Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration", "deprecated": false, "secret": false, "description": "To use an existing reactive stream engine configuration." },
     "serviceType": { "kind": "property", "displayName": "Service Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "Set the type of the underlying reactive streams implementation to use. The implementation is looked up from the registry or using a ServiceLoader, the default implementation is DefaultCamelReactiveStreamsService" }
   },
   "properties": {
diff --git a/components-starter/camel-reactive-streams-starter/src/main/docs/reactive-streams-starter.adoc b/components-starter/camel-reactive-streams-starter/src/main/docs/reactive-streams-starter.adoc
index eb279f7..e3d3c76 100644
--- a/components-starter/camel-reactive-streams-starter/src/main/docs/reactive-streams-starter.adoc
+++ b/components-starter/camel-reactive-streams-starter/src/main/docs/reactive-streams-starter.adoc
@@ -17,7 +17,7 @@ When using reactive-streams with Spring Boot make sure to use the following Mave
 ----
 
 
-The component supports 7 options, which are listed below.
+The component supports 10 options, which are listed below.
 
 
 
@@ -28,8 +28,11 @@ The component supports 7 options, which are listed below.
 | *camel.component.reactive-streams.basic-property-binding* | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | Boolean
 | *camel.component.reactive-streams.bridge-error-handler* | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean
 | *camel.component.reactive-streams.enabled* | Whether to enable auto configuration of the reactive-streams component. This is enabled by default. |  | Boolean
-| *camel.component.reactive-streams.internal-engine-configuration* | Configures the internal engine for Reactive Streams. The option is a org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration type. |  | String
 | *camel.component.reactive-streams.lazy-start-producer* | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is pro [...]
+| *camel.component.reactive-streams.reactive-streams-engine-configuration* | To use an existing reactive stream engine configuration. The option is a org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration type. |  | String
 | *camel.component.reactive-streams.service-type* | Set the type of the underlying reactive streams implementation to use. The implementation is looked up from the registry or using a ServiceLoader, the default implementation is DefaultCamelReactiveStreamsService |  | String
+| *camel.component.reactive-streams.thread-pool-max-size* | The maximum number of threads used by the reactive streams internal engine. | 10 | Integer
+| *camel.component.reactive-streams.thread-pool-min-size* | The minimum number of threads used by the reactive streams internal engine. |  | Integer
+| *camel.component.reactive-streams.thread-pool-name* | The name of the thread pool used by the reactive streams internal engine. | CamelReactiveStreamsWorker | String
 |===
 // spring-boot-auto-configure options: END
diff --git a/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsComponentConfiguration.java b/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsComponentConfiguration.java
index a1b50d4..257932b 100644
--- a/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsComponentConfiguration.java
+++ b/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsComponentConfiguration.java
@@ -39,6 +39,20 @@ public class ReactiveStreamsComponentConfiguration
      */
     private Boolean enabled;
     /**
+     * The maximum number of threads used by the reactive streams internal
+     * engine.
+     */
+    private Integer threadPoolMaxSize = 10;
+    /**
+     * The minimum number of threads used by the reactive streams internal
+     * engine.
+     */
+    private Integer threadPoolMinSize;
+    /**
+     * The name of the thread pool used by the reactive streams internal engine.
+     */
+    private String threadPoolName = "CamelReactiveStreamsWorker";
+    /**
      * Allows for bridging the consumer to the Camel routing Error Handler,
      * which mean any exceptions occurred while the consumer is trying to pickup
      * incoming messages, or the likes, will now be processed as a message and
@@ -69,10 +83,10 @@ public class ReactiveStreamsComponentConfiguration
      */
     private Boolean basicPropertyBinding = false;
     /**
-     * Configures the internal engine for Reactive Streams. The option is a
+     * To use an existing reactive stream engine configuration. The option is a
      * org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration type.
      */
-    private String internalEngineConfiguration;
+    private String reactiveStreamsEngineConfiguration;
     /**
      * Set the type of the underlying reactive streams implementation to use.
      * The implementation is looked up from the registry or using a
@@ -81,6 +95,30 @@ public class ReactiveStreamsComponentConfiguration
      */
     private String serviceType;
 
+    public Integer getThreadPoolMaxSize() {
+        return threadPoolMaxSize;
+    }
+
+    public void setThreadPoolMaxSize(Integer threadPoolMaxSize) {
+        this.threadPoolMaxSize = threadPoolMaxSize;
+    }
+
+    public Integer getThreadPoolMinSize() {
+        return threadPoolMinSize;
+    }
+
+    public void setThreadPoolMinSize(Integer threadPoolMinSize) {
+        this.threadPoolMinSize = threadPoolMinSize;
+    }
+
+    public String getThreadPoolName() {
+        return threadPoolName;
+    }
+
+    public void setThreadPoolName(String threadPoolName) {
+        this.threadPoolName = threadPoolName;
+    }
+
     public Boolean getBridgeErrorHandler() {
         return bridgeErrorHandler;
     }
@@ -114,13 +152,13 @@ public class ReactiveStreamsComponentConfiguration
         this.basicPropertyBinding = basicPropertyBinding;
     }
 
-    public String getInternalEngineConfiguration() {
-        return internalEngineConfiguration;
+    public String getReactiveStreamsEngineConfiguration() {
+        return reactiveStreamsEngineConfiguration;
     }
 
-    public void setInternalEngineConfiguration(
-            String internalEngineConfiguration) {
-        this.internalEngineConfiguration = internalEngineConfiguration;
+    public void setReactiveStreamsEngineConfiguration(
+            String reactiveStreamsEngineConfiguration) {
+        this.reactiveStreamsEngineConfiguration = reactiveStreamsEngineConfiguration;
     }
 
     public String getServiceType() {
diff --git a/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsServiceAutoConfiguration.java b/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsServiceAutoConfiguration.java
index f6206d7..529690f 100644
--- a/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsServiceAutoConfiguration.java
+++ b/components-starter/camel-reactive-streams-starter/src/main/java/org/apache/camel/component/reactive/streams/springboot/ReactiveStreamsServiceAutoConfiguration.java
@@ -16,20 +16,17 @@
  */
 package org.apache.camel.component.reactive.streams.springboot;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.reactive.streams.ReactiveStreamsHelper;
 import org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService;
 import org.apache.camel.component.reactive.streams.engine.ReactiveStreamsEngineConfiguration;
-import org.apache.camel.support.IntrospectionSupport;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Lazy;
 
@@ -46,13 +43,19 @@ public class ReactiveStreamsServiceAutoConfiguration {
     @Bean
     @ConditionalOnMissingBean
     @ConditionalOnClass(CamelContext.class)
-    public CamelReactiveStreamsService camelReactiveStreamsService() throws Exception {
+    public CamelReactiveStreamsService camelReactiveStreamsService(ApplicationContext ac) throws Exception {
         ReactiveStreamsEngineConfiguration engineConfiguration = new ReactiveStreamsEngineConfiguration();
 
-        if (configuration.getInternalEngineConfiguration() != null) {
-            Map<String, Object> parameters = new HashMap<>();
-            IntrospectionSupport.getProperties(configuration.getInternalEngineConfiguration(), parameters, null, false);
-            IntrospectionSupport.setProperties(context, context.getTypeConverter(), engineConfiguration, parameters);
+        if (configuration.getReactiveStreamsEngineConfiguration() != null) {
+            engineConfiguration = ac.getBean(configuration.getReactiveStreamsEngineConfiguration(), ReactiveStreamsEngineConfiguration.class);
+        } else {
+            engineConfiguration.setThreadPoolName(configuration.getThreadPoolName());
+            if (configuration.getThreadPoolMinSize() != null) {
+                engineConfiguration.setThreadPoolMinSize(configuration.getThreadPoolMinSize());
+            }
+            if (configuration.getThreadPoolMaxSize() != null) {
+                engineConfiguration.setThreadPoolMinSize(configuration.getThreadPoolMaxSize());
+            }
         }
 
         return ReactiveStreamsHelper.resolveReactiveStreamsService(context, configuration.getServiceType(), engineConfiguration);
diff --git a/components-starter/camel-reactive-streams-starter/src/test/java/org/apache/camel/component/reactive/streams/springboot/test/ReactiveStreamsAutoConfigurationTest.java b/components-starter/camel-reactive-streams-starter/src/test/java/org/apache/camel/component/reactive/streams/springboot/test/ReactiveStreamsAutoConfigurationTest.java
index 6e5432f..fc59374 100644
--- a/components-starter/camel-reactive-streams-starter/src/test/java/org/apache/camel/component/reactive/streams/springboot/test/ReactiveStreamsAutoConfigurationTest.java
+++ b/components-starter/camel-reactive-streams-starter/src/test/java/org/apache/camel/component/reactive/streams/springboot/test/ReactiveStreamsAutoConfigurationTest.java
@@ -51,7 +51,7 @@ import static org.junit.Assert.assertTrue;
         ReactiveStreamsAutoConfigurationTest.TestConfiguration.class
     },
     properties = {
-        "camel.component.reactive-streams.internal-engine-configuration.thread-pool-name=rs-test"
+        "camel.component.reactive-streams.thread-pool-name=rs-test"
     }
 )
 public class ReactiveStreamsAutoConfigurationTest {
@@ -61,17 +61,17 @@ public class ReactiveStreamsAutoConfigurationTest {
     private CamelReactiveStreamsService reactiveStreamsService;
 
     @Test
-    public void testConfiguration() throws InterruptedException {
+    public void testConfiguration() throws Exception {
         CamelReactiveStreamsService service = CamelReactiveStreams.get(context);
         assertTrue(service instanceof DefaultCamelReactiveStreamsService);
         assertEquals(service, reactiveStreamsService);
 
         ReactiveStreamsComponent component = context.getComponent(ReactiveStreamsConstants.SCHEME, ReactiveStreamsComponent.class);
-        assertEquals("rs-test", component.getInternalEngineConfiguration().getThreadPoolName());
+        assertEquals("rs-test", component.getThreadPoolName());
     }
 
     @Test
-    public void testService() throws InterruptedException {
+    public void testService() throws Exception {
         CamelReactiveStreamsService service = CamelReactiveStreams.get(context);
         CountDownLatch latch = new CountDownLatch(1);
         String[] res = new String[1];