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 2018/03/08 10:45:46 UTC
[camel] branch master updated (0ff3783 -> fd11cdd)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.
from 0ff3783 CAMEL-12335: Fixed NPE in camel-sjms consumer if synchronous=true. Polished the logging code a bit.
new 441bcf2 CAMEL-12330: Added camel-example-rabbitmq
new 2434c8f CAMEL-12330: Polished
new ea21180 CAMEL-12330: Make camel-rabbitmq endpoint uri syntax like the other messaging components. Deprecate the old syntax.
new 0c0face CAMEL-12330: Allow to configure more option on rabbitmq component level.
new fd11cdd CAMEL-12330: Allow to configure more option on rabbitmq component level.
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../src/main/docs/rabbitmq-component.adoc | 76 +++++++++---
.../component/rabbitmq/RabbitMQComponent.java | 135 +++++++++++++++++++--
.../camel/component/rabbitmq/RabbitMQEndpoint.java | 37 +++---
.../component/rabbitmq/RabbitMQComponentTest.java | 4 +-
.../component/rabbitmq/RabbitMQEndpointTest.java | 7 +-
.../RabbitMQLookupConnectionFactoryTest.java} | 32 ++---
examples/README.adoc | 8 +-
.../pom.xml | 10 +-
examples/camel-example-rabbitmq/readme.adoc | 29 +++++
.../java/sample/camel/SampleCamelApplication.java | 13 ++
.../main/java/sample/camel/SampleCamelRouter.java | 14 +--
.../src/main/resources/application.properties | 13 +-
examples/pom.xml | 1 +
.../springboot/RabbitMQComponentConfiguration.java | 81 +++++++++++++
14 files changed, 364 insertions(+), 96 deletions(-)
copy components/{camel-zipkin/src/test/java/org/apache/camel/zipkin/ZipkinSpanReporterInRegistryTest.java => camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQLookupConnectionFactoryTest.java} (61%)
copy examples/{camel-example-spring-boot => camel-example-rabbitmq}/pom.xml (94%)
create mode 100644 examples/camel-example-rabbitmq/readme.adoc
copy examples/{camel-example-validator-spring-boot => camel-example-rabbitmq}/src/main/java/sample/camel/SampleCamelApplication.java (73%)
copy examples/{camel-example-spring-boot => camel-example-rabbitmq}/src/main/java/sample/camel/SampleCamelRouter.java (75%)
copy examples/{camel-example-spring-boot-xml => camel-example-rabbitmq}/src/main/resources/application.properties (84%)
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.
[camel] 04/05: CAMEL-12330: Allow to configure more option on
rabbitmq component level.
Posted by da...@apache.org.
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
commit 0c0facee6d16e44441b8fb93f3189c2d4e7047b2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 10:28:28 2018 +0100
CAMEL-12330: Allow to configure more option on rabbitmq component level.
---
.../src/main/docs/rabbitmq-component.adoc | 8 +++++--
.../component/rabbitmq/RabbitMQComponent.java | 28 ++++++++++++++++++++++
.../camel/component/rabbitmq/RabbitMQEndpoint.java | 7 +++---
.../main/java/sample/camel/SampleCamelRouter.java | 4 ++--
.../src/main/resources/application.properties | 9 +++----
.../springboot/RabbitMQComponentConfiguration.java | 24 +++++++++++++++++++
6 files changed, 69 insertions(+), 11 deletions(-)
diff --git a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
index 6fd3f65..35f1e2f 100644
--- a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
+++ b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
@@ -37,7 +37,7 @@ exchange name determines which exchange the queue will bind to.
=== Options
// component options: START
-The RabbitMQ component supports 3 options which are listed below.
+The RabbitMQ component supports 5 options which are listed below.
@@ -46,6 +46,8 @@ The RabbitMQ component supports 3 options which are listed below.
| Name | Description | Default | Type
| *hostname* (common) | The hostname of the running rabbitmq instance or cluster. | | String
| *portNumber* (common) | Port number for the host with the running rabbitmq instance or cluster. | 5672 | int
+| *username* (security) | Username in case of authenticated access | guest | String
+| *password* (security) | Password for authenticated access | guest | String
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
|===
// component options: END
@@ -70,7 +72,7 @@ with the following path and query parameters:
|===
-==== Query Parameters (58 parameters):
+==== Query Parameters (60 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
@@ -86,7 +88,9 @@ with the following path and query parameters:
| *durable* (common) | If we are declaring a durable exchange (the exchange will survive a server restart) | true | boolean
| *exchangeType* (common) | The exchange type such as direct or topic. | direct | String
| *exclusive* (common) | Exclusive queues may only be accessed by the current connection, and are deleted when that connection closes. | false | boolean
+| *hostname* (common) | The hostname of the running rabbitmq instance or cluster. | | String
| *passive* (common) | Passive queues depend on the queue already to be available at RabbitMQ. | false | boolean
+| *portNumber* (common) | Port number for the host with the running rabbitmq instance or cluster. Default value is 5672. | | int
| *queue* (common) | The queue to receive messages from | | String
| *routingKey* (common) | The routing key to use when binding a consumer queue to the exchange. For producer routing keys, you set the header rabbitmq.ROUTING_KEY. | | String
| *skipExchangeDeclare* (common) | This can be used if we need to declare the queue but not the exchange | false | boolean
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index 2ef6077..39515a3 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -42,6 +42,10 @@ public class RabbitMQComponent extends UriEndpointComponent {
private String hostname;
@Metadata(label = "common", defaultValue = "5672")
private int portNumber;
+ @Metadata(label = "security", defaultValue = ConnectionFactory.DEFAULT_USER, secret = true)
+ private String username = ConnectionFactory.DEFAULT_USER;
+ @Metadata(label = "security", defaultValue = ConnectionFactory.DEFAULT_PASS, secret = true)
+ private String password = ConnectionFactory.DEFAULT_PASS;
public RabbitMQComponent() {
super(RabbitMQEndpoint.class);
@@ -89,6 +93,8 @@ public class RabbitMQComponent extends UriEndpointComponent {
}
endpoint.setHostname(host);
endpoint.setPortNumber(port);
+ endpoint.setUsername(getUsername());
+ endpoint.setPassword(getPassword());
endpoint.setExchangeName(exchangeName);
endpoint.setClientProperties(clientProperties);
endpoint.setTrustManager(trustManager);
@@ -135,4 +141,26 @@ public class RabbitMQComponent extends UriEndpointComponent {
this.portNumber = portNumber;
}
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * Username in case of authenticated access
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Password for authenticated access
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
}
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
index be24f65..1342a98 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
@@ -53,12 +53,13 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
// header to indicate that the message body needs to be de-serialized
public static final String SERIALIZE_HEADER = "CamelSerialize";
- private String hostname;
- private int portNumber;
-
@UriPath
@Metadata(required = "true")
private String exchangeName;
+ @UriParam(label = "common")
+ private String hostname;
+ @UriParam(label = "common")
+ private int portNumber;
@UriParam(label = "security", defaultValue = ConnectionFactory.DEFAULT_USER, secret = true)
private String username = ConnectionFactory.DEFAULT_USER;
@UriParam(label = "security", defaultValue = ConnectionFactory.DEFAULT_PASS, secret = true)
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
index aff28f9..46dfe0c 100644
--- a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
@@ -31,9 +31,9 @@ public class SampleCamelRouter extends RouteBuilder {
public void configure() throws Exception {
from("timer:hello?period=1000")
.transform(simple("Random number ${random(0,100)}"))
- .to("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}");
+ .to("rabbitmq:foo");
- from("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}")
+ from("rabbitmq:foo")
.log("From RabbitMQ: ${body}");
}
diff --git a/examples/camel-example-rabbitmq/src/main/resources/application.properties b/examples/camel-example-rabbitmq/src/main/resources/application.properties
index 7d7c800..279b2cd 100644
--- a/examples/camel-example-rabbitmq/src/main/resources/application.properties
+++ b/examples/camel-example-rabbitmq/src/main/resources/application.properties
@@ -33,10 +33,11 @@ management.security.enabled = false
# turn on actuator health check
endpoints.health.enabled = true
-rabbit-host=localhost
-rabbit-port=5672
-rabbit-user=guest
-rabbit-password=guest
+# configure connection to the rabbit mq broker
+camel.component.rabbitmq.hostname=localhost
+camel.component.rabbitmq.port-number=5672
+camel.component.rabbitmq.username=guest
+camel.component.rabbitmq.password=guest
# to configure logging levels
#logging.level.org.springframework = INFO
diff --git a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
index 2796eff..163f892 100644
--- a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
@@ -41,6 +41,14 @@ public class RabbitMQComponentConfiguration
*/
private Integer portNumber = 5672;
/**
+ * Username in case of authenticated access
+ */
+ private String username = "guest";
+ /**
+ * Password for authenticated access
+ */
+ private String password = "guest";
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
@@ -63,6 +71,22 @@ public class RabbitMQComponentConfiguration
this.portNumber = portNumber;
}
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.
[camel] 02/05: CAMEL-12330: Polished
Posted by da...@apache.org.
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
commit 2434c8f62505cbb995fc814ea7131d174fd15fbb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 10:06:37 2018 +0100
CAMEL-12330: Polished
---
.../camel/component/rabbitmq/RabbitMQEndpoint.java | 23 +++++++++++-----------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
index d3567b5..4c01a43 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
@@ -17,7 +17,6 @@
package org.apache.camel.component.rabbitmq;
import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -37,7 +36,6 @@ import com.rabbitmq.client.Envelope;
import org.apache.camel.AsyncEndpoint;
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
-import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
@@ -177,14 +175,11 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
private long publisherAcknowledgementsTimeout;
@UriParam(label = "producer")
private boolean guaranteedDeliveries;
- // camel-jms supports this setting but it is not currently configurable in
- // camel-rabbitmq
+ // camel-jms supports this setting but it is not currently configurable in camel-rabbitmq
private boolean useMessageIDAsCorrelationID = true;
- // camel-jms supports this setting but it is not currently configurable in
- // camel-rabbitmq
+ // camel-jms supports this setting but it is not currently configurable in camel-rabbitmq
private String replyToType = ReplyToType.Temporary.name();
- // camel-jms supports this setting but it is not currently configurable in
- // camel-rabbitmq
+ // camel-jms supports this setting but it is not currently configurable in camel-rabbitmq
private String replyTo;
private final RabbitMQMessageConverter messageConverter = new RabbitMQMessageConverter();
@@ -194,11 +189,11 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
public RabbitMQEndpoint() {
}
- public RabbitMQEndpoint(String endpointUri, RabbitMQComponent component) throws URISyntaxException {
+ public RabbitMQEndpoint(String endpointUri, RabbitMQComponent component) {
super(endpointUri, component);
}
- public RabbitMQEndpoint(String endpointUri, RabbitMQComponent component, ConnectionFactory connectionFactory) throws URISyntaxException {
+ public RabbitMQEndpoint(String endpointUri, RabbitMQComponent component, ConnectionFactory connectionFactory) {
super(endpointUri, component);
this.connectionFactory = connectionFactory;
}
@@ -849,6 +844,7 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
return bindingArgs;
}
+ @Deprecated
public ArgsConfigurer getQueueArgsConfigurer() {
return queueArgsConfigurer;
}
@@ -856,12 +852,14 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
/**
* Set the configurer for setting the queue args in Channel.queueDeclare
*
- * @Deprecated Use args instead e.g arg.queue.x-message-ttl=1000
+ * @deprecated Use args instead e.g arg.queue.x-message-ttl=1000
*/
+ @Deprecated
public void setQueueArgsConfigurer(ArgsConfigurer queueArgsConfigurer) {
this.queueArgsConfigurer = queueArgsConfigurer;
}
+ @Deprecated
public ArgsConfigurer getExchangeArgsConfigurer() {
return exchangeArgsConfigurer;
}
@@ -870,8 +868,9 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
* Set the configurer for setting the exchange args in
* Channel.exchangeDeclare
*
- * @Deprecated Use args instead e.g arg.exchange.x-message-ttl=1000
+ * @deprecated Use args instead e.g arg.exchange.x-message-ttl=1000
*/
+ @Deprecated
public void setExchangeArgsConfigurer(ArgsConfigurer exchangeArgsConfigurer) {
this.exchangeArgsConfigurer = exchangeArgsConfigurer;
}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.
[camel] 01/05: CAMEL-12330: Added camel-example-rabbitmq
Posted by da...@apache.org.
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
commit 441bcf2b0e9220efe0666144bcaa2c2d1e1623cb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 10:01:41 2018 +0100
CAMEL-12330: Added camel-example-rabbitmq
---
examples/README.adoc | 8 +-
examples/camel-example-rabbitmq/pom.xml | 151 +++++++++++++++++++++
examples/camel-example-rabbitmq/readme.adoc | 29 ++++
.../java/sample/camel/SampleCamelApplication.java | 37 +++++
.../main/java/sample/camel/SampleCamelRouter.java | 40 ++++++
.../src/main/resources/application.properties | 45 ++++++
examples/pom.xml | 1 +
7 files changed, 309 insertions(+), 2 deletions(-)
diff --git a/examples/README.adoc b/examples/README.adoc
index be893ac..04b6ee3 100644
--- a/examples/README.adoc
+++ b/examples/README.adoc
@@ -11,7 +11,7 @@ View the individual example READMEs for details.
### Examples
// examples: START
-Number of Examples: 101 (8 deprecated)
+Number of Examples: 102 (8 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -139,7 +139,9 @@ Number of Examples: 101 (8 deprecated)
| link:camel-example-activemq-tomcat/README.md[ActiveMQ Tomcat] (camel-example-activemq-tomcat) | Messaging | An example using ActiveMQ Broker and Camel with Apache Tomcat
-| link:camel-example-artemis-amqp-blueprint/README.md[Artemis Amqp Blueprint] (camel-example-artemis-amqp-blueprint) | Messaging | Demonstrates ActiveMQ Artemis using Camel's AMQP component. The example includes a JUnit showcasing how to embed for testing an AMQP enabled Artemis broker.
+| link:camel-example-artemis-amqp-blueprint/README.md[Artemis Amqp Blueprint] (camel-example-artemis-amqp-blueprint) | Messaging | Demonstrates ActiveMQ Artemis using Camel's AMQP component. The example includes a JUnit showcasing how
+ to embed for testing an AMQP enabled Artemis broker.
+
| link:camel-example-artemis-large-messages/README.md[Artemis Large Messages] (camel-example-artemis-large-messages) | Messaging | Demonstrates sending large messages (handles GBs in size) between Apache Camel and ActiveMQ Artemis in streaming mode
@@ -151,6 +153,8 @@ Number of Examples: 101 (8 deprecated)
| link:camel-example-kafka/README.adoc[Kafka] (camel-example-kafka) | Messaging | An example for Kafka
+| link:camel-example-rabbitmq/readme.adoc[Rabbitmq] (camel-example-rabbitmq) | Messaging | An example showing how to work with Camel and RabbitMQ
+
| link:camel-example-spring-boot-activemq/readme.adoc[Spring Boot Activemq] (camel-example-spring-boot-activemq) | Messaging | An example showing how to work with Camel, ActiveMQ and Spring Boot
| link:camel-example-spring-jms/README.md[Spring JMS] (camel-example-spring-jms) | Messaging | An example using Spring XML to talk to the JMS server from different kind of client techniques
diff --git a/examples/camel-example-rabbitmq/pom.xml b/examples/camel-example-rabbitmq/pom.xml
new file mode 100644
index 0000000..cfdd685
--- /dev/null
+++ b/examples/camel-example-rabbitmq/pom.xml
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>2.21.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-rabbitmq</artifactId>
+ <name>Camel :: Example :: RabbitMQ</name>
+ <description>An example showing how to work with Camel and RabbitMQ</description>
+
+ <properties>
+ <category>Messaging</category>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <spring.boot-version>${spring-boot-version}</spring.boot-version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Spring Boot BOM -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring.boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <!-- Camel BOM -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-dependencies</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-undertow</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-actuator</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-rabbitmq-starter</artifactId>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <!-- allows to fail if not all routes are fully covered during testing -->
+<!--
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+-->
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>jdk9-build</id>
+ <activation>
+ <jdk>9</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>--add-modules java.xml.bind --add-opens java.base/java.lang=ALL-UNNAMED</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/examples/camel-example-rabbitmq/readme.adoc b/examples/camel-example-rabbitmq/readme.adoc
new file mode 100644
index 0000000..c82d5d3
--- /dev/null
+++ b/examples/camel-example-rabbitmq/readme.adoc
@@ -0,0 +1,29 @@
+= Camel Example RabbitMQ
+
+This example shows how to work with a simple Apache Camel application that routes message to RabbitMQ.
+
+The example generates messages using timer trigger, routes them via RabbitMQ and logs to message.
+
+=== Configuring RabbitMQ
+
+The sample application uses `localhost:5672` to connect to the RabbitMQ broker.
+This can be configured in the `application.properties` file.
+
+The login information is the default `guest/guest` account, which can be configured
+in the `application.properties` file as well.
+
+== How to run
+
+The sample requires a RabbitMQ broker to be running.
+
+You can for example easily start RabbitMQ via Docker
+
+ docker run -it -p 5672:5672 --hostname my-rabbit --name some-rabbit rabbitmq:3
+
+Then you can run this example using
+
+ mvn spring-boot:run
+
+== More information
+
+You can find more information about Apache Camel at the website: http://camel.apache.org/
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
new file mode 100644
index 0000000..5d9304a
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
@@ -0,0 +1,37 @@
+/**
+ * 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 sample.camel;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+//CHECKSTYLE:OFF
+/**
+ * A sample Spring Boot application that starts the Camel routes.
+ */
+@SpringBootApplication
+public class SampleCamelApplication {
+
+ /**
+ * A main method to start this application.
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(SampleCamelApplication.class, args);
+ }
+
+}
+//CHECKSTYLE:ON
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
new file mode 100644
index 0000000..aff28f9
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
@@ -0,0 +1,40 @@
+/**
+ * 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 sample.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+/**
+ * A simple Camel route that triggers from a timer and routes to RabbitMQ
+ * <p/>
+ * Use <tt>@Component</tt> to make Camel auto detect this route when starting.
+ */
+@Component
+public class SampleCamelRouter extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("timer:hello?period=1000")
+ .transform(simple("Random number ${random(0,100)}"))
+ .to("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}");
+
+ from("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}")
+ .log("From RabbitMQ: ${body}");
+ }
+
+}
diff --git a/examples/camel-example-rabbitmq/src/main/resources/application.properties b/examples/camel-example-rabbitmq/src/main/resources/application.properties
new file mode 100644
index 0000000..7d7c800
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/resources/application.properties
@@ -0,0 +1,45 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# the name of Camel
+camel.springboot.name = SampleCamel
+
+# to automatic shutdown the JVM after a period of time
+#camel.springboot.duration-max-seconds=60
+#camel.springboot.duration-max-messages=100
+
+# add for example: &repeatCount=5 to the timer endpoint to make Camel idle
+#camel.springboot.duration-max-idle-seconds=15
+
+# properties used in the Camel route and beans
+# --------------------------------------------
+
+# all access to actuator endpoints without security
+management.security.enabled = false
+# turn on actuator health check
+endpoints.health.enabled = true
+
+rabbit-host=localhost
+rabbit-port=5672
+rabbit-user=guest
+rabbit-password=guest
+
+# to configure logging levels
+#logging.level.org.springframework = INFO
+#logging.level.org.apache.camel.spring.boot = INFO
+#logging.level.org.apache.camel.impl = DEBUG
+#logging.level.sample.camel = DEBUG
diff --git a/examples/pom.xml b/examples/pom.xml
index 50a1eda..5c55f5e 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -80,6 +80,7 @@
<module>camel-example-olingo4-blueprint</module>
<module>camel-example-opentracing</module>
<module>camel-example-pojo-messaging</module>
+ <module>camel-example-rabbitmq</module>
<module>camel-example-reactive-streams</module>
<module>camel-example-reload</module>
<module>camel-example-reportincident</module>
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.
[camel] 05/05: CAMEL-12330: Allow to configure more option on
rabbitmq component level.
Posted by da...@apache.org.
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
commit fd11cddb05e53719e3512fc3833901f7c918c406
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 11:07:36 2018 +0100
CAMEL-12330: Allow to configure more option on rabbitmq component level.
---
.../src/main/docs/rabbitmq-component.adoc | 54 ++++++++++++++++------
.../component/rabbitmq/RabbitMQComponent.java | 48 ++++++++++++++++++-
.../camel/component/rabbitmq/RabbitMQEndpoint.java | 4 +-
.../component/rabbitmq/RabbitMQComponentTest.java | 4 +-
.../RabbitMQLookupConnectionFactoryTest.java | 44 ++++++++++++++++++
.../java/sample/camel/SampleCamelApplication.java | 13 ++++++
.../src/main/resources/application.properties | 3 +-
.../springboot/RabbitMQComponentConfiguration.java | 33 +++++++++++++
8 files changed, 183 insertions(+), 20 deletions(-)
diff --git a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
index 35f1e2f..30eca55 100644
--- a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
+++ b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
@@ -23,11 +23,21 @@ for this component:
=== URI format
+The old syntax is *deprecated*:
[source,text]
----
rabbitmq://hostname[:port]/exchangeName?[options]
----
+Instead the hostname and port is configured on the component level, or
+can be provided as uri query parameters instead.
+
+The new syntax is:
+[source,text]
+----
+rabbitmq:exchangeName?[options]
+----
+
Where *hostname* is the hostname of the running rabbitmq instance or
cluster. Port is optional and if not specified then defaults to the
RabbitMQ client default (5672). The exchange name determines which
@@ -37,7 +47,7 @@ exchange name determines which exchange the queue will bind to.
=== Options
// component options: START
-The RabbitMQ component supports 5 options which are listed below.
+The RabbitMQ component supports 7 options which are listed below.
@@ -48,6 +58,8 @@ The RabbitMQ component supports 5 options which are listed below.
| *portNumber* (common) | Port number for the host with the running rabbitmq instance or cluster. | 5672 | int
| *username* (security) | Username in case of authenticated access | guest | String
| *password* (security) | Password for authenticated access | guest | String
+| *connectionFactory* (common) | To use a custom RabbitMQ connection factory. When this option is set, all connection options (connectionTimeout, requestedChannelMax...) set on URI are not used | | ConnectionFactory
+| *autoDetectConnection Factory* (common) | Whether to auto-detect looking up RabbitMQ connection factory from the registry. When enabled and a single instance of the connection factory is found then it will be used. An explicit connection factory can be configured on the component or endpoint level which takes precedence. | true | boolean
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
|===
// component options: END
@@ -79,6 +91,7 @@ with the following path and query parameters:
|===
| Name | Description | Default | Type
| *autoDelete* (common) | If it is true, the exchange will be deleted when it is no longer in use | true | boolean
+| *connectionFactory* (common) | To use a custom RabbitMQ connection factory. When this option is set, all connection options (connectionTimeout, requestedChannelMax...) set on URI are not used | | ConnectionFactory
| *connectionTimeout* (common) | Connection timeout | 60000 | int
| *deadLetterExchange* (common) | The name of the dead letter exchange | | String
| *deadLetterExchangeType* (common) | The type of the dead letter exchange | direct | String
@@ -120,7 +133,6 @@ with the following path and query parameters:
| *automaticRecoveryEnabled* (advanced) | Enables connection automatic recovery (uses connection implementation that performs automatic recovery when connection shutdown is not initiated by the application) | | Boolean
| *bindingArgs* (advanced) | *Deprecated* Key/value args for configuring the queue binding parameters when declare=true | | Map
| *clientProperties* (advanced) | Connection client properties (client info used in negotiating with the server) | | Map
-| *connectionFactory* (advanced) | To use a custom RabbitMQ connection factory. When this option is set, all connection options (connectionTimeout, requestedChannelMax...) set on URI are not used | | ConnectionFactory
| *exchangeArgs* (advanced) | *Deprecated* Key/value args for configuring the exchange parameters when declare=true | | Map
| *exchangeArgsConfigurer* (advanced) | *Deprecated* Set the configurer for setting the exchange args in Channel.exchangeDeclare | | ArgsConfigurer
| *networkRecoveryInterval* (advanced) | Network recovery interval in milliseconds (interval used when recovering from network failure) | 5000 | Integer
@@ -164,7 +176,19 @@ And then refer to the connection factory in the endpoint uri as shown below:
<camelContext>
<route>
<from uri="direct:rabbitMQEx2"/>
- <to uri="rabbitmq://localhost:5672/ex2?connectionFactory=#rabbitConnectionFactory"/>
+ <to uri="rabbitmq:ex2?connectionFactory=#rabbitConnectionFactory"/>
+ </route>
+</camelContext>
+----
+
+From Camel 2.21 onwards the `ConnectionFactory` is auto-detected by default, so you can just do
+
+[source,xml]
+----
+<camelContext>
+ <route>
+ <from uri="direct:rabbitMQEx2"/>
+ <to uri="rabbitmq:ex2"/>
</route>
</camelContext>
----
@@ -255,7 +279,7 @@ routing key B,
[source,java]
----
-from("rabbitmq://localhost/A?routingKey=B")
+from("rabbitmq:A?routingKey=B")
----
To receive messages from a queue with a single thread with auto
@@ -263,21 +287,21 @@ acknowledge disabled.
[source,java]
----
-from("rabbitmq://localhost/A?routingKey=B&threadPoolSize=1&autoAck=false")
+from("rabbitmq:A?routingKey=B&threadPoolSize=1&autoAck=false")
----
To send messages to an exchange called C
[source,java]
----
-to("rabbitmq://localhost/C")
+to("rabbitmq:C")
----
Declaring a headers exchange and queue
[source,java]
----
-from("rabbitmq://localhost/ex?exchangeType=headers&queue=q&bindingArgs=#bindArgs")
+from("rabbitmq:ex?exchangeType=headers&queue=q&bindingArgs=#bindArgs")
----
and place corresponding `Map<String, Object>` with the id of "bindArgs" in the Registry.
@@ -299,8 +323,8 @@ in the example below with foo -> bar:
[source,java]
----
-from("rabbitmq://localhost/foo")
- .to("rabbitmq://localhost/bar")
+from("rabbitmq:foo")
+ .to("rabbitmq:bar")
----
Then beware that Camel will route the message to itself, eg foo -> foo. So why is that?
@@ -315,17 +339,17 @@ To avoid this you need to either:
[source,java]
----
-from("rabbitmq://localhost/foo")
+from("rabbitmq:foo")
.removeHeader("rabbitmq.EXCHANGE_NAME")
- .to("rabbitmq://localhost/bar")
+ .to("rabbitmq:bar")
----
- Or turn on `bridgeEndpoint` mode on the producer:
[source,java]
----
-from("rabbitmq://localhost/foo")
- .to("rabbitmq://localhost/bar?bridgeEndpoint=true")
+from("rabbitmq:foo")
+ .to("rabbitmq:bar?bridgeEndpoint=true")
----
From Camel 2.21 onwards this has been improved so you can easily route between exchanges.
@@ -335,8 +359,8 @@ For example to send to cheese exchange you can do
[source,java]
----
-from("rabbitmq://localhost/foo")
+from("rabbitmq:foo")
.setHeader("rabbitmq.EXCHANGE_OVERRIDE_NAME", constant("cheese"))
- .to("rabbitmq://localhost/bar")
+ .to("rabbitmq:bar")
----
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index 39515a3..d17fef4 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.rabbitmq;
import java.net.URI;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import javax.net.ssl.TrustManager;
import com.rabbitmq.client.ConnectionFactory;
@@ -46,6 +48,10 @@ public class RabbitMQComponent extends UriEndpointComponent {
private String username = ConnectionFactory.DEFAULT_USER;
@Metadata(label = "security", defaultValue = ConnectionFactory.DEFAULT_PASS, secret = true)
private String password = ConnectionFactory.DEFAULT_PASS;
+ @Metadata(label = "common")
+ private ConnectionFactory connectionFactory;
+ @Metadata(label = "common", defaultValue = "true")
+ private boolean autoDetectConnectionFactory = true;
public RabbitMQComponent() {
super(RabbitMQEndpoint.class);
@@ -81,7 +87,22 @@ public class RabbitMQComponent extends UriEndpointComponent {
}
// ConnectionFactory reference
- ConnectionFactory connectionFactory = resolveAndRemoveReferenceParameter(params, "connectionFactory", ConnectionFactory.class);
+ ConnectionFactory connectionFactory = resolveAndRemoveReferenceParameter(params, "connectionFactory", ConnectionFactory.class, getConnectionFactory());
+
+ // try to lookup if there is a single instance in the registry of the ConnectionFactory
+ if (connectionFactory == null && isAutoDetectConnectionFactory()) {
+ Map<String, ConnectionFactory> map = getCamelContext().getRegistry().findByTypeWithName(ConnectionFactory.class);
+ if (map != null && map.size() == 1) {
+ Map.Entry<String, ConnectionFactory> entry = map.entrySet().iterator().next();
+ connectionFactory = entry.getValue();
+ String name = entry.getKey();
+ if (name == null) {
+ name = "anonymous";
+ }
+ LOG.info("Auto-detected single instance: {} of type ConnectionFactory in Registry to be used as ConnectionFactory when creating endpoint: {}", name, uri);
+ }
+ }
+
@SuppressWarnings("unchecked")
Map<String, Object> clientProperties = resolveAndRemoveReferenceParameter(params, "clientProperties", Map.class);
TrustManager trustManager = resolveAndRemoveReferenceParameter(params, "trustManager", TrustManager.class);
@@ -163,4 +184,29 @@ public class RabbitMQComponent extends UriEndpointComponent {
this.password = password;
}
+ public ConnectionFactory getConnectionFactory() {
+ return connectionFactory;
+ }
+
+ /**
+ * To use a custom RabbitMQ connection factory. When this option is set, all
+ * connection options (connectionTimeout, requestedChannelMax...) set on URI
+ * are not used
+ */
+ public void setConnectionFactory(ConnectionFactory connectionFactory) {
+ this.connectionFactory = connectionFactory;
+ }
+
+ public boolean isAutoDetectConnectionFactory() {
+ return autoDetectConnectionFactory;
+ }
+
+ /**
+ * Whether to auto-detect looking up RabbitMQ connection factory from the registry.
+ * When enabled and a single instance of the connection factory is found then it will be used.
+ * An explicit connection factory can be configured on the component or endpoint level which takes precedence.
+ */
+ public void setAutoDetectConnectionFactory(boolean autoDetectConnectionFactory) {
+ this.autoDetectConnectionFactory = autoDetectConnectionFactory;
+ }
}
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
index 1342a98..480fe73 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
@@ -66,6 +66,8 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
private String password = ConnectionFactory.DEFAULT_PASS;
@UriParam(defaultValue = ConnectionFactory.DEFAULT_VHOST)
private String vhost = ConnectionFactory.DEFAULT_VHOST;
+ @UriParam(label = "common")
+ private ConnectionFactory connectionFactory;
@UriParam(label = "consumer,advanced", defaultValue = "10")
private int threadPoolSize = 10;
@UriParam(label = "consumer", defaultValue = "true")
@@ -109,8 +111,6 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
@UriParam(label = "advanced")
private Map<String, Object> clientProperties;
@UriParam(label = "advanced")
- private ConnectionFactory connectionFactory;
- @UriParam(label = "advanced")
private Boolean automaticRecoveryEnabled;
@UriParam(label = "advanced", defaultValue = "5000")
private Integer networkRecoveryInterval = 5000;
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQComponentTest.java b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQComponentTest.java
index 5506aab..15de74b 100644
--- a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQComponentTest.java
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQComponentTest.java
@@ -92,7 +92,9 @@ public class RabbitMQComponentTest {
String uri = "rabbitmq:special.host:14/queuey";
String remaining = "special.host:14/queuey";
- return new RabbitMQComponent(context).createEndpoint(uri, remaining, params);
+ RabbitMQComponent comp = new RabbitMQComponent(context);
+ comp.setAutoDetectConnectionFactory(false);
+ return comp.createEndpoint(uri, remaining, params);
}
@Test
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQLookupConnectionFactoryTest.java b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQLookupConnectionFactoryTest.java
new file mode 100644
index 0000000..438688c
--- /dev/null
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQLookupConnectionFactoryTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.component.rabbitmq;
+
+import com.rabbitmq.client.ConnectionFactory;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class RabbitMQLookupConnectionFactoryTest extends CamelTestSupport {
+
+ private ConnectionFactory myConnectionFactory;
+
+ protected JndiRegistry createRegistry() throws Exception {
+ myConnectionFactory = new ConnectionFactory();
+ myConnectionFactory.setHost("myhost");
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("myConnectionFactory", myConnectionFactory);
+ return registry;
+ }
+
+ @Test
+ public void testLookupConnectionFactory() throws Exception {
+ RabbitMQEndpoint endpoint = context.getEndpoint("rabbitmq:myexchange", RabbitMQEndpoint.class);
+ assertNotNull(endpoint);
+ assertSame(endpoint.getConnectionFactory(), myConnectionFactory);
+ }
+
+}
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
index 5d9304a..5839aad 100644
--- a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
@@ -16,8 +16,10 @@
*/
package sample.camel;
+import com.rabbitmq.client.ConnectionFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
//CHECKSTYLE:OFF
/**
@@ -33,5 +35,16 @@ public class SampleCamelApplication {
SpringApplication.run(SampleCamelApplication.class, args);
}
+ /* You can also configure the RabbitMQ ConnectionFactory using Java code style
+ @Bean
+ public ConnectionFactory rabbitConnectionFactory() {
+ ConnectionFactory cf = new ConnectionFactory();
+ cf.setHost("localhost");
+ cf.setPort(5672);
+ cf.setUsername("cameltest");
+ cf.setPassword("cameltest");
+ return cf;
+ }
+ */
}
//CHECKSTYLE:ON
diff --git a/examples/camel-example-rabbitmq/src/main/resources/application.properties b/examples/camel-example-rabbitmq/src/main/resources/application.properties
index 279b2cd..e414fc0 100644
--- a/examples/camel-example-rabbitmq/src/main/resources/application.properties
+++ b/examples/camel-example-rabbitmq/src/main/resources/application.properties
@@ -33,7 +33,8 @@ management.security.enabled = false
# turn on actuator health check
endpoints.health.enabled = true
-# configure connection to the rabbit mq broker
+# configure connection to the rabbit mq broker using camel-rabbitmq style
+# note you can also configure from Java code, see SampleCamelApplication.java
camel.component.rabbitmq.hostname=localhost
camel.component.rabbitmq.port-number=5672
camel.component.rabbitmq.username=guest
diff --git a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
index 163f892..9bee754 100644
--- a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
@@ -17,8 +17,10 @@
package org.apache.camel.component.rabbitmq.springboot;
import javax.annotation.Generated;
+import com.rabbitmq.client.ConnectionFactory;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* The rabbitmq component allows you produce and consume messages from RabbitMQ
@@ -49,6 +51,20 @@ public class RabbitMQComponentConfiguration
*/
private String password = "guest";
/**
+ * To use a custom RabbitMQ connection factory. When this option is set, all
+ * connection options (connectionTimeout, requestedChannelMax...) set on URI
+ * are not used
+ */
+ @NestedConfigurationProperty
+ private ConnectionFactory connectionFactory;
+ /**
+ * Whether to auto-detect looking up RabbitMQ connection factory from the
+ * registry. When enabled and a single instance of the connection factory is
+ * found then it will be used. An explicit connection factory can be
+ * configured on the component or endpoint level which takes precedence.
+ */
+ private Boolean autoDetectConnectionFactory = true;
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
@@ -87,6 +103,23 @@ public class RabbitMQComponentConfiguration
this.password = password;
}
+ public ConnectionFactory getConnectionFactory() {
+ return connectionFactory;
+ }
+
+ public void setConnectionFactory(ConnectionFactory connectionFactory) {
+ this.connectionFactory = connectionFactory;
+ }
+
+ public Boolean getAutoDetectConnectionFactory() {
+ return autoDetectConnectionFactory;
+ }
+
+ public void setAutoDetectConnectionFactory(
+ Boolean autoDetectConnectionFactory) {
+ this.autoDetectConnectionFactory = autoDetectConnectionFactory;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.
[camel] 03/05: CAMEL-12330: Make camel-rabbitmq endpoint uri syntax
like the other messaging components. Deprecate the old syntax.
Posted by da...@apache.org.
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
commit ea21180b131509a8af94deb34546ce5b72d453b5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 10:22:40 2018 +0100
CAMEL-12330: Make camel-rabbitmq endpoint uri syntax like the other messaging components. Deprecate the old syntax.
---
.../src/main/docs/rabbitmq-component.adoc | 18 +++++--
.../component/rabbitmq/RabbitMQComponent.java | 59 ++++++++++++++++++----
.../camel/component/rabbitmq/RabbitMQEndpoint.java | 7 +--
.../component/rabbitmq/RabbitMQEndpointTest.java | 7 +--
.../springboot/RabbitMQComponentConfiguration.java | 24 +++++++++
5 files changed, 91 insertions(+), 24 deletions(-)
diff --git a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
index 2727679..6fd3f65 100644
--- a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
+++ b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
@@ -37,7 +37,17 @@ exchange name determines which exchange the queue will bind to.
=== Options
// component options: START
-The RabbitMQ component has no options.
+The RabbitMQ component supports 3 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *hostname* (common) | The hostname of the running rabbitmq instance or cluster. | | String
+| *portNumber* (common) | Port number for the host with the running rabbitmq instance or cluster. | 5672 | int
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
+|===
// component options: END
@@ -45,19 +55,17 @@ The RabbitMQ component has no options.
The RabbitMQ endpoint is configured using URI syntax:
----
-rabbitmq:hostname:portNumber/exchangeName
+rabbitmq:exchangeName
----
with the following path and query parameters:
-==== Path Parameters (3 parameters):
+==== Path Parameters (1 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
-| *hostname* | *Required* The hostname of the running rabbitmq instance or cluster. | | String
-| *portNumber* | *Required* Port number for the host with the running rabbitmq instance or cluster. Default value is 5672. | 5672 | int
| *exchangeName* | *Required* The exchange name determines which exchange produced messages will sent to. In the case of consumers, the exchange name determines which exchange the queue will bind to. | | String
|===
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index 237ba1a..2ef6077 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -22,9 +22,9 @@ import java.util.Map;
import javax.net.ssl.TrustManager;
import com.rabbitmq.client.ConnectionFactory;
-
import org.apache.camel.CamelContext;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.Metadata;
import org.apache.camel.util.IntrospectionSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +38,11 @@ public class RabbitMQComponent extends UriEndpointComponent {
private static final Logger LOG = LoggerFactory.getLogger(RabbitMQComponent.class);
+ @Metadata(label = "common")
+ private String hostname;
+ @Metadata(label = "common", defaultValue = "5672")
+ private int portNumber;
+
public RabbitMQComponent() {
super(RabbitMQEndpoint.class);
}
@@ -50,12 +55,25 @@ public class RabbitMQComponent extends UriEndpointComponent {
protected RabbitMQEndpoint createEndpoint(String uri,
String remaining,
Map<String, Object> params) throws Exception {
- URI host = new URI("http://" + remaining);
- String hostname = host.getHost();
- int portNumber = host.getPort();
- String exchangeName = ""; // We need to support the exchange to be "" the path is empty
- if (host.getPath().trim().length() > 1) {
- exchangeName = host.getPath().substring(1);
+
+ String host = getHostname();
+ int port = getPortNumber();
+ String exchangeName = remaining;
+
+ if (remaining.contains(":") || remaining.contains("/")) {
+ LOG.warn("The old syntax rabbitmq://hostname:port/exchangeName is deprecated. You should configure the hostname on the component or ConnectionFactory");
+ try {
+ URI u = new URI("http://" + remaining);
+ host = u.getHost();
+ port = u.getPort();
+ if (u.getPath().trim().length() > 1) {
+ exchangeName = u.getPath().substring(1);
+ } else {
+ exchangeName = "";
+ }
+ } catch (Throwable e) {
+ // ignore
+ }
}
// ConnectionFactory reference
@@ -69,8 +87,8 @@ public class RabbitMQComponent extends UriEndpointComponent {
} else {
endpoint = new RabbitMQEndpoint(uri, this, connectionFactory);
}
- endpoint.setHostname(hostname);
- endpoint.setPortNumber(portNumber);
+ endpoint.setHostname(host);
+ endpoint.setPortNumber(port);
endpoint.setExchangeName(exchangeName);
endpoint.setClientProperties(clientProperties);
endpoint.setTrustManager(trustManager);
@@ -94,4 +112,27 @@ public class RabbitMQComponent extends UriEndpointComponent {
return endpoint;
}
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ /**
+ * The hostname of the running rabbitmq instance or cluster.
+ */
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ }
+
+ public int getPortNumber() {
+ return portNumber;
+ }
+
+ /**
+ * Port number for the host with the running rabbitmq instance or cluster.
+ */
+ public void setPortNumber(int portNumber) {
+ this.portNumber = portNumber;
+ }
+
}
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
index 4c01a43..be24f65 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
@@ -48,17 +48,14 @@ import org.apache.camel.spi.UriPath;
* The rabbitmq component allows you produce and consume messages from
* <a href="http://www.rabbitmq.com/">RabbitMQ</a> instances.
*/
-@UriEndpoint(firstVersion = "2.12.0", scheme = "rabbitmq", title = "RabbitMQ", syntax = "rabbitmq:hostname:portNumber/exchangeName", consumerClass = RabbitMQConsumer.class, label = "messaging")
+@UriEndpoint(firstVersion = "2.12.0", scheme = "rabbitmq", title = "RabbitMQ", syntax = "rabbitmq:exchangeName", consumerClass = RabbitMQConsumer.class, label = "messaging")
public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
// header to indicate that the message body needs to be de-serialized
public static final String SERIALIZE_HEADER = "CamelSerialize";
- @UriPath
- @Metadata(required = "true")
private String hostname;
- @UriPath(defaultValue = "5672")
- @Metadata(required = "true")
private int portNumber;
+
@UriPath
@Metadata(required = "true")
private String exchangeName;
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
index f998a08..6cdc284 100644
--- a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
@@ -95,11 +95,8 @@ public class RabbitMQEndpointTest extends CamelTestSupport {
RabbitMQEndpoint endpoint1 = context.getEndpoint("rabbitmq:localhost/", RabbitMQEndpoint.class);
assertEquals("Get a wrong exchange name", "", endpoint1.getExchangeName());
- RabbitMQEndpoint endpoint2 = context.getEndpoint("rabbitmq:localhost?autoAck=false", RabbitMQEndpoint.class);
- assertEquals("Get a wrong exchange name", "", endpoint2.getExchangeName());
-
- RabbitMQEndpoint endpoint3 = context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);
- assertEquals("Get a wrong exchange name", "exchange", endpoint3.getExchangeName());
+ RabbitMQEndpoint endpoint2 = context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);
+ assertEquals("Get a wrong exchange name", "exchange", endpoint2.getExchangeName());
}
@Test
diff --git a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
index cc9c40d..2796eff 100644
--- a/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-rabbitmq-starter/src/main/java/org/apache/camel/component/rabbitmq/springboot/RabbitMQComponentConfiguration.java
@@ -33,12 +33,36 @@ public class RabbitMQComponentConfiguration
ComponentConfigurationPropertiesCommon {
/**
+ * The hostname of the running rabbitmq instance or cluster.
+ */
+ private String hostname;
+ /**
+ * Port number for the host with the running rabbitmq instance or cluster.
+ */
+ private Integer portNumber = 5672;
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
*/
private Boolean resolvePropertyPlaceholders = true;
+ public String getHostname() {
+ return hostname;
+ }
+
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ }
+
+ public Integer getPortNumber() {
+ return portNumber;
+ }
+
+ public void setPortNumber(Integer portNumber) {
+ this.portNumber = portNumber;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.