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 2019/12/03 14:55:36 UTC

[camel] 01/02: CAMEL-14213: camel-jms - Should only lookup CF if a TX manager has not been configured either, as the TX manager woudld come with its own. Allow to configure these autowrire options on component level also.

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

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

commit 03200cd1bb728e4484da1d5178c0fc333f28fe82
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 25 10:42:01 2019 +0100

    CAMEL-14213: camel-jms - Should only lookup CF if a TX manager has not been configured either, as the TX manager woudld come with its own. Allow to configure these autowrire options on component level also.
---
 .../camel-jms/src/main/docs/jms-component.adoc     |  4 ++-
 .../apache/camel/component/jms/JmsComponent.java   | 36 +++++++++++++---------
 .../modules/ROOT/pages/jms-component.adoc          |  4 ++-
 .../jms/springboot/JmsComponentConfiguration.java  | 32 +++++++++++++++++++
 4 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/components/camel-jms/src/main/docs/jms-component.adoc b/components/camel-jms/src/main/docs/jms-component.adoc
index 1e39d6c..48e97b4 100644
--- a/components/camel-jms/src/main/docs/jms-component.adoc
+++ b/components/camel-jms/src/main/docs/jms-component.adoc
@@ -182,13 +182,15 @@ about these properties by consulting the relevant Spring documentation.
 
 
 // component options: START
-The JMS component supports 82 options, which are listed below.
+The JMS component supports 84 options, which are listed below.
 
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *allowAutoWired ConnectionFactory* (advanced) | Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default. | false | boolean
+| *allowAutoWired DestinationResolver* (advanced) | Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured. If only one instance of DestinationResolver is found then it will be used. This is enabled by default. | false | boolean
 | *configuration* (advanced) | To use a shared JMS configuration |  | JmsConfiguration
 | *acceptMessagesWhile Stopping* (consumer) | Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on t [...]
 | *allowReplyManagerQuick Stop* (consumer) | Whether the DefaultMessageListenerContainer used in the reply managers for request-reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag. | false  [...]
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
index 5c37b97..495c122 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.jms;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
-
 import javax.jms.ConnectionFactory;
 import javax.jms.ExceptionListener;
 import javax.jms.Message;
@@ -60,6 +59,12 @@ public class JmsComponent extends HeaderFilterStrategyComponent {
     @Metadata(label = "advanced", description = "To use the given MessageCreatedStrategy which are invoked when Camel creates new instances"
             + " of javax.jms.Message objects when Camel is sending a JMS message.")
     private MessageCreatedStrategy messageCreatedStrategy;
+    @Metadata(label = "advanced", description = "Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured."
+            + " If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.")
+    private boolean allowAutoWiredConnectionFactory = true;
+    @Metadata(label = "advanced", description = "Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured."
+            + " If only one instance of DestinationResolver is found then it will be used. This is enabled by default.")
+    private boolean allowAutoWiredDestinationResolver = true;
 
     public JmsComponent() {
         this.configuration = createConfiguration();
@@ -135,25 +140,27 @@ public class JmsComponent extends HeaderFilterStrategyComponent {
     }
 
     /**
-     * Subclasses can override to prevent the jms configuration from being
-     * setup to use an auto-wired the connection factory that's found in the spring
-     * application context.
-     *
-     * @return true by default
+     * Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured.
+     * If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.
      */
     public boolean isAllowAutoWiredConnectionFactory() {
-        return true;
+        return allowAutoWiredConnectionFactory;
+    }
+
+    public void setAllowAutoWiredConnectionFactory(boolean allowAutoWiredConnectionFactory) {
+        this.allowAutoWiredConnectionFactory = allowAutoWiredConnectionFactory;
     }
 
     /**
-     * Subclasses can override to prevent the jms configuration from being
-     * setup to use an auto-wired the destination resolved that's found in the spring
-     * application context.
-     *
-     * @return true by default
+     * Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured.
+     * If only one instance of DestinationResolver is found then it will be used. This is enabled by default.
      */
     public boolean isAllowAutoWiredDestinationResolver() {
-        return true;
+        return allowAutoWiredDestinationResolver;
+    }
+
+    public void setAllowAutoWiredDestinationResolver(boolean allowAutoWiredDestinationResolver) {
+        this.allowAutoWiredDestinationResolver = allowAutoWiredDestinationResolver;
     }
 
     /**
@@ -1223,7 +1230,8 @@ public class JmsComponent extends HeaderFilterStrategyComponent {
 
     @Override
     protected void doStart() throws Exception {
-        if (configuration.getConnectionFactory() == null && isAllowAutoWiredConnectionFactory()) {
+        // only attempt to set connection factory if there is no transaction manager
+        if (configuration.getConnectionFactory() == null && configuration.getTransactionManager() == null && isAllowAutoWiredConnectionFactory()) {
             Set<ConnectionFactory> beans = getCamelContext().getRegistry().findByType(ConnectionFactory.class);
             if (beans.size() == 1) {
                 ConnectionFactory cf = beans.iterator().next();
diff --git a/docs/components/modules/ROOT/pages/jms-component.adoc b/docs/components/modules/ROOT/pages/jms-component.adoc
index 8202fd4..8eca6f6 100644
--- a/docs/components/modules/ROOT/pages/jms-component.adoc
+++ b/docs/components/modules/ROOT/pages/jms-component.adoc
@@ -183,13 +183,15 @@ about these properties by consulting the relevant Spring documentation.
 
 
 // component options: START
-The JMS component supports 82 options, which are listed below.
+The JMS component supports 84 options, which are listed below.
 
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *allowAutoWired ConnectionFactory* (advanced) | Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default. | false | boolean
+| *allowAutoWired DestinationResolver* (advanced) | Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured. If only one instance of DestinationResolver is found then it will be used. This is enabled by default. | false | boolean
 | *configuration* (advanced) | To use a shared JMS configuration |  | JmsConfiguration
 | *acceptMessagesWhile Stopping* (consumer) | Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on t [...]
 | *allowReplyManagerQuick Stop* (consumer) | Whether the DefaultMessageListenerContainer used in the reply managers for request-reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag. | false  [...]
diff --git a/platforms/spring-boot/components-starter/camel-jms-starter/src/main/java/org/apache/camel/component/jms/springboot/JmsComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-jms-starter/src/main/java/org/apache/camel/component/jms/springboot/JmsComponentConfiguration.java
index f2add8d..10b97ee 100644
--- a/platforms/spring-boot/components-starter/camel-jms-starter/src/main/java/org/apache/camel/component/jms/springboot/JmsComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-jms-starter/src/main/java/org/apache/camel/component/jms/springboot/JmsComponentConfiguration.java
@@ -42,6 +42,20 @@ public class JmsComponentConfiguration
      */
     private Boolean enabled;
     /**
+     * Whether to auto-discover ConnectionFactory from the registry, if no
+     * connection factory has been configured. If only one instance of
+     * ConnectionFactory is found then it will be used. This is enabled by
+     * default.
+     */
+    private Boolean allowAutoWiredConnectionFactory = false;
+    /**
+     * Whether to auto-discover DestinationResolver from the registry, if no
+     * destination resolver has been configured. If only one instance of
+     * DestinationResolver is found then it will be used. This is enabled by
+     * default.
+     */
+    private Boolean allowAutoWiredDestinationResolver = false;
+    /**
      * To use a shared JMS configuration. The option is a
      * org.apache.camel.component.jms.JmsConfiguration type.
      */
@@ -639,6 +653,24 @@ public class JmsComponentConfiguration
      */
     private Boolean bridgeErrorHandler = false;
 
+    public Boolean getAllowAutoWiredConnectionFactory() {
+        return allowAutoWiredConnectionFactory;
+    }
+
+    public void setAllowAutoWiredConnectionFactory(
+            Boolean allowAutoWiredConnectionFactory) {
+        this.allowAutoWiredConnectionFactory = allowAutoWiredConnectionFactory;
+    }
+
+    public Boolean getAllowAutoWiredDestinationResolver() {
+        return allowAutoWiredDestinationResolver;
+    }
+
+    public void setAllowAutoWiredDestinationResolver(
+            Boolean allowAutoWiredDestinationResolver) {
+        this.allowAutoWiredDestinationResolver = allowAutoWiredDestinationResolver;
+    }
+
     public String getConfiguration() {
         return configuration;
     }