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.git
The following commit(s) were added to refs/heads/master by this push: new 40efcd0 CAMEL-14643: jms/activemq component should wire autowired connection factory in init phase so its pre-configured and will be used. As otherwise when for example using spring boot activemq then it will fallback to default broker url instead of using the autowired. 40efcd0 is described below commit 40efcd0ad2450bb6d879c0777bba2e8ade88b3ee Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed May 6 19:41:08 2020 +0200 CAMEL-14643: jms/activemq component should wire autowired connection factory in init phase so its pre-configured and will be used. As otherwise when for example using spring boot activemq then it will fallback to default broker url instead of using the autowired. --- .../component/activemq/ActiveMQConfiguration.java | 37 ++++++++++++++-------- .../apache/camel/component/jms/JmsComponent.java | 4 ++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java index f9b6f85..7c505f6 100644 --- a/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java +++ b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java @@ -141,23 +141,32 @@ public class ActiveMQConfiguration extends JmsConfiguration { @Override public void setConnectionFactory(ConnectionFactory connectionFactory) { - if (customBrokerURL) { - // okay a custom broker url was configured which we want to ensure - // the real target connection factory knows about - ConnectionFactory target = connectionFactory; - if (target instanceof CachingConnectionFactory) { - CachingConnectionFactory ccf = (CachingConnectionFactory) target; - target = ccf.getTargetConnectionFactory(); - } - if (target instanceof DelegatingConnectionFactory) { - DelegatingConnectionFactory dcf = (DelegatingConnectionFactory) target; - target = dcf.getTargetConnectionFactory(); - } - if (target instanceof ActiveMQConnectionFactory) { - ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) target; + ActiveMQConnectionFactory acf = null; + + ConnectionFactory target = connectionFactory; + if (target instanceof CachingConnectionFactory) { + CachingConnectionFactory ccf = (CachingConnectionFactory) target; + target = ccf.getTargetConnectionFactory(); + } + if (target instanceof DelegatingConnectionFactory) { + DelegatingConnectionFactory dcf = (DelegatingConnectionFactory) target; + target = dcf.getTargetConnectionFactory(); + } + if (target instanceof ActiveMQConnectionFactory) { + acf = (ActiveMQConnectionFactory) target; + } + + if (acf != null) { + if (customBrokerURL) { + // okay a custom broker url was configured which we want to ensure + // the real target connection factory knows about acf.setBrokerURL(brokerURL); + } else { + // its the opposite the target has the brokerURL which we want to set on this + setBrokerURL(acf.getBrokerURL()); } } + super.setConnectionFactory(connectionFactory); } 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 4cb3389..3103a32 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 @@ -1009,7 +1009,7 @@ public class JmsComponent extends HeaderFilterStrategyComponent { // ------------------------------------------------------------------------- @Override - protected void doStart() throws Exception { + protected void doInit() throws Exception { // only attempt to set connection factory if there is no transaction manager if (configuration.getConnectionFactory() == null && configuration.getOrCreateTransactionManager() == null && isAllowAutoWiredConnectionFactory()) { Set<ConnectionFactory> beans = getCamelContext().getRegistry().findByType(ConnectionFactory.class); @@ -1034,6 +1034,8 @@ public class JmsComponent extends HeaderFilterStrategyComponent { if (getHeaderFilterStrategy() == null) { setHeaderFilterStrategy(new JmsHeaderFilterStrategy(configuration.isIncludeAllJMSXProperties())); } + + super.doInit(); } @Override