This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit cee922120d5b690a6f910c987d4536773e67ab32 Author: JiriOndrusek <[email protected]> AuthorDate: Wed Feb 10 15:04:56 2021 +0100 camel-spring-rabbitmq - new component #2128 --- catalog/pom.xml | 13 ++ .../reference/extensions/spring-rabbitmq.adoc | 33 +++++ .../reference/components/spring-rabbitmq.adoc | 14 ++- extensions/pom.xml | 1 + extensions/spring-rabbitmq/deployment/pom.xml | 71 +++++++++++ .../deployment/SpringRabbitmqProcessor.java | 37 ++++++ extensions/spring-rabbitmq/pom.xml | 39 ++++++ extensions/spring-rabbitmq/runtime/pom.xml | 121 +++++++++++++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 31 +++++ integration-tests/pom.xml | 1 + integration-tests/spring-rabbitmq/pom.xml | 133 +++++++++++++++++++++ .../SpringRabbitmqConnectionFactoryProducer.java | 51 ++++++++ .../spring/rabbitmq/it/SpringRabbitmqResource.java | 93 ++++++++++++++ .../rabbitmq/it/SpringRabbitmqRouteBuilder.java | 37 ++++++ .../spring/rabbitmq/it/SpringRabbitmqIT.java | 24 ++++ .../spring/rabbitmq/it/SpringRabbitmqTest.java | 112 +++++++++++++++++ .../rabbitmq/it/SpringRabbitmqTestResource.java | 78 ++++++++++++ poms/bom/pom.xml | 15 +++ tooling/scripts/test-categories.yaml | 1 + 19 files changed, 904 insertions(+), 1 deletion(-) diff --git a/catalog/pom.xml b/catalog/pom.xml index 86f4439..a2b6bb9 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -3481,6 +3481,19 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-sql</artifactId> <version>${project.version}</version> <type>pom</type> diff --git a/docs/modules/ROOT/pages/reference/extensions/spring-rabbitmq.adoc b/docs/modules/ROOT/pages/reference/extensions/spring-rabbitmq.adoc new file mode 100644 index 0000000..bff1f77 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/spring-rabbitmq.adoc @@ -0,0 +1,33 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page += Spring RabbitMQ +:cq-artifact-id: camel-quarkus-spring-rabbitmq +:cq-native-supported: true +:cq-status: Stable +:cq-description: Send and receive messages from RabbitMQ using Spring RabbitMQ client. +:cq-deprecated: false +:cq-jvm-since: 1.7.0 +:cq-native-since: 1.7.0 + +[.badges] +[.badge-key]##JVM since##[.badge-supported]##1.7.0## [.badge-key]##Native since##[.badge-supported]##1.7.0## + +Send and receive messages from RabbitMQ using Spring RabbitMQ client. + +== What's inside + +* xref:{cq-camel-components}::spring-rabbitmq-component.adoc[Spring RabbitMQ component], URI syntax: `spring-rabbitmq:exchangeName` + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. diff --git a/docs/modules/ROOT/partials/reference/components/spring-rabbitmq.adoc b/docs/modules/ROOT/partials/reference/components/spring-rabbitmq.adoc index a509c1d..fa57234 100644 --- a/docs/modules/ROOT/partials/reference/components/spring-rabbitmq.adoc +++ b/docs/modules/ROOT/partials/reference/components/spring-rabbitmq.adoc @@ -1 +1,13 @@ -// Empty partial for a Camel bit unsupported by Camel Quarkus to avoid warnings when this file is included from a Camel page +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +:cq-artifact-id: camel-quarkus-spring-rabbitmq +:cq-artifact-id-base: spring-rabbitmq +:cq-native-supported: true +:cq-status: Stable +:cq-deprecated: false +:cq-jvm-since: 1.7.0 +:cq-native-since: 1.7.0 +:cq-camel-part-name: spring-rabbitmq +:cq-camel-part-title: Spring RabbitMQ +:cq-camel-part-description: Send and receive messages from RabbitMQ using Spring RabbitMQ client. +:cq-extension-page-title: Spring RabbitMQ diff --git a/extensions/pom.xml b/extensions/pom.xml index f23b94e..f6fa647 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -211,6 +211,7 @@ <module>snakeyaml</module> <module>soap</module> <module>solr</module> + <module>spring-rabbitmq</module> <module>sql</module> <module>ssh</module> <module>stax</module> diff --git a/extensions/spring-rabbitmq/deployment/pom.xml b/extensions/spring-rabbitmq/deployment/pom.xml new file mode 100644 index 0000000..4d4a636 --- /dev/null +++ b/extensions/spring-rabbitmq/deployment/pom.xml @@ -0,0 +1,71 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-spring-rabbitmq-deployment</artifactId> + <name>Camel Quarkus :: Spring RabbitMQ :: Deployment</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-commons-logging-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-spring-deployment</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/spring-rabbitmq/deployment/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/deployment/SpringRabbitmqProcessor.java b/extensions/spring-rabbitmq/deployment/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/deployment/SpringRabbitmqProcessor.java new file mode 100644 index 0000000..d5c6a52 --- /dev/null +++ b/extensions/spring-rabbitmq/deployment/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/deployment/SpringRabbitmqProcessor.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 org.apache.camel.quarkus.component.spring.rabbitmq.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; +import org.springframework.amqp.rabbit.connection.ChannelProxy; + +class SpringRabbitmqProcessor { + + private static final String FEATURE = "camel-spring-rabbitmq"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + NativeImageProxyDefinitionBuildItem initProxies() { + return new NativeImageProxyDefinitionBuildItem(ChannelProxy.class.getCanonicalName()); + } +} diff --git a/extensions/spring-rabbitmq/pom.xml b/extensions/spring-rabbitmq/pom.xml new file mode 100644 index 0000000..19f6470 --- /dev/null +++ b/extensions/spring-rabbitmq/pom.xml @@ -0,0 +1,39 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-spring-rabbitmq-parent</artifactId> + <name>Camel Quarkus :: Spring RabbitMQ</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/spring-rabbitmq/runtime/pom.xml b/extensions/spring-rabbitmq/runtime/pom.xml new file mode 100644 index 0000000..b84c680 --- /dev/null +++ b/extensions/spring-rabbitmq/runtime/pom.xml @@ -0,0 +1,121 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> + <name>Camel Quarkus :: Spring RabbitMQ :: Runtime</name> + <description>Send and receive messages from RabbitMQ using Spring RabbitMQ client.</description> + + <properties> + <camel.quarkus.jvmSince>1.7.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>1.7.0</camel.quarkus.nativeSince> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-rabbitmq</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-commons-logging</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-spring</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + + + <profiles> + <profile> + <id>full</id> + <activation> + <property> + <name>!quickly</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals> + <goal>update-extension-doc-page</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/extensions/spring-rabbitmq/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/spring-rabbitmq/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..723d1e4 --- /dev/null +++ b/extensions/spring-rabbitmq/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,31 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel Spring RabbitMQ" +description: "Send and receive messages from RabbitMQ using Spring RabbitMQ client" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/spring-rabbitmq.html" + categories: + - "integration" + status: + - "stable" diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index b2455af..e44a762 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -178,6 +178,7 @@ <module>smallrye-reactive-messaging</module> <module>soap</module> <module>solr</module> + <module>spring-rabbitmq</module> <module>sql</module> <module>ssh</module> <module>stax</module> diff --git a/integration-tests/spring-rabbitmq/pom.xml b/integration-tests/spring-rabbitmq/pom.xml new file mode 100644 index 0000000..146ff3d --- /dev/null +++ b/integration-tests/spring-rabbitmq/pom.xml @@ -0,0 +1,133 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>1.7.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-spring-rabbitmq</artifactId> + <name>Camel Quarkus :: Integration Tests :: Spring RabbitMQ</name> + <description>Integration tests for Camel Quarkus Spring RabbitMQ extension</description> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-testcontainers-support</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>rabbitmq</artifactId> + <scope>test</scope> + </dependency> + + <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqConnectionFactoryProducer.java b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqConnectionFactoryProducer.java new file mode 100644 index 0000000..c05468c --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqConnectionFactoryProducer.java @@ -0,0 +1,51 @@ +/* + * 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.quarkus.component.spring.rabbitmq.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import javax.ws.rs.Produces; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; + +public class SpringRabbitmqConnectionFactoryProducer { + + @ConfigProperty(name = SpringRabbitmqResource.PARAMETER_PORT) + Integer port; + + @ConfigProperty(name = SpringRabbitmqResource.PARAMETER_HOSTNAME) + String hostname; + + @ConfigProperty(name = SpringRabbitmqResource.PARAMETER_USERNAME) + String usernane; + + @ConfigProperty(name = SpringRabbitmqResource.PARAMETER_PASSWORD) + String password; + + @Produces + @ApplicationScoped + @Named("connectionFactory") + public ConnectionFactory produceConnectionFactory() { + CachingConnectionFactory cf = new CachingConnectionFactory(); + cf.setUri(String.format("amqp://%s:%d", hostname, port)); + cf.setUsername(usernane); + cf.setPassword(password); + return cf; + } +} diff --git a/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqResource.java b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqResource.java new file mode 100644 index 0000000..39d1607 --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqResource.java @@ -0,0 +1,93 @@ +/* + * 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.quarkus.component.spring.rabbitmq.it; + +import java.util.concurrent.Executors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.ProducerTemplate; +import org.jboss.logging.Logger; + +@Path("/spring-rabbitmq") +@ApplicationScoped +public class SpringRabbitmqResource { + private static final Logger LOG = Logger.getLogger(SpringRabbitmqResource.class); + + public static final String PARAMETER_PORT = "camel.quarkus.spring-rabbitmq.test.port"; + public static final String PARAMETER_HOSTNAME = "camel.quarkus.spring-rabbitmq.test.hostname"; + public static final String PARAMETER_USERNAME = "camel.quarkus.spring-rabbitmq.test.username"; + public static final String PARAMETER_PASSWORD = "camel.quarkus.spring-rabbitmq.test.password"; + + public static final String ROUTING_KEY_IN_OUT = "foo.bar"; + public static final String EXCHANGE_IN_OUT = "inOut"; + + public static final String POLLING_QUEUE_NAME = "pollingQueue"; + + public static final String DIRECT_IN_OUT = "direct:inOut"; + public static final String DIRECT_POLLING = "direct:polling"; + + public static final String QUERY_ROUTING_KEY = "routingKey"; + public static final String QUERY_DIRECT = "fromDirect"; + public static final String QUERY_EXCHANGE = "exchange"; + public static final String QUERY_TIMEOUT = "timeout"; + + @Inject + ProducerTemplate producerTemplate; + + @Inject + ConsumerTemplate consumerTemplate; + + @Path("/getFromDirect") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String getFromDirect(@QueryParam(QUERY_DIRECT) String directName, @QueryParam(QUERY_TIMEOUT) int timeout) { + final String message = timeout > 0 ? consumerTemplate.receiveBody(directName, timeout, String.class) + : consumerTemplate.receiveBodyNoWait(directName, String.class); + return message; + } + + @Path("/send") + @POST + @Consumes(MediaType.TEXT_PLAIN) + public void send(String message, @QueryParam(QUERY_EXCHANGE) String exchange, + @QueryParam(QUERY_ROUTING_KEY) String routingKey) { + String url = String.format("spring-rabbitmq:" + exchange + "?routingKey=%s&autoDeclare=true", routingKey); + producerTemplate.sendBody(url, message); + } + + @Path("/startPolling") + @POST + public void startPolling(@QueryParam(QUERY_EXCHANGE) String exchange, + @QueryParam(QUERY_ROUTING_KEY) String routingKey) { + // use another thread for polling consumer to demonstrate that we can wait before + // the message is sent to the queue + Executors.newSingleThreadExecutor().execute(() -> { + String url = String.format("spring-rabbitmq:%s?queues=%s&routingKey=%s", exchange, POLLING_QUEUE_NAME, routingKey); + String body = consumerTemplate.receiveBody(url, String.class); + producerTemplate.sendBody(DIRECT_POLLING, "Polling Hello " + body); + }); + } +} diff --git a/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqRouteBuilder.java b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqRouteBuilder.java new file mode 100644 index 0000000..442c313 --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/main/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqRouteBuilder.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 org.apache.camel.quarkus.component.spring.rabbitmq.it; + +import javax.enterprise.context.ApplicationScoped; + +import org.apache.camel.builder.RouteBuilder; + +@ApplicationScoped +public class SpringRabbitmqRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + String url = String.format( + "spring-rabbitmq:%s?queues=myqueue&routingKey=%s&connectionFactory=#connectionFactory&autoDeclare=true", + SpringRabbitmqResource.EXCHANGE_IN_OUT, SpringRabbitmqResource.ROUTING_KEY_IN_OUT); + + from(url) + .transform(body().prepend("Hello ")) + .to(SpringRabbitmqResource.DIRECT_IN_OUT); + } +} diff --git a/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqIT.java b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqIT.java new file mode 100644 index 0000000..52812e3 --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqIT.java @@ -0,0 +1,24 @@ +/* + * 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.quarkus.component.spring.rabbitmq.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class SpringRabbitmqIT extends SpringRabbitmqTest { + +} diff --git a/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTest.java b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTest.java new file mode 100644 index 0000000..255bef8 --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTest.java @@ -0,0 +1,112 @@ +/* + * 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.quarkus.component.spring.rabbitmq.it; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.response.Response; +import org.junit.jupiter.api.Test; +import org.springframework.amqp.core.AmqpAdmin; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitAdmin; + +import static org.hamcrest.Matchers.is; + +@QuarkusTest +@QuarkusTestResource(SpringRabbitmqTestResource.class) +class SpringRabbitmqTest { + + private final static String EXCHANGE_POLLING = "polling"; + private final static String ROUTING_KEY_POLLING = "pollingKey"; + private ConnectionFactory connectionFactory; + + @Test + public void testInOut() { + //direct has to be empty + getFromDirect(SpringRabbitmqResource.DIRECT_IN_OUT) + .then() + .statusCode(204); + + sendToExchange(SpringRabbitmqResource.EXCHANGE_IN_OUT, SpringRabbitmqResource.ROUTING_KEY_IN_OUT, "Sheldon"); + + getFromDirect(SpringRabbitmqResource.DIRECT_IN_OUT) + .then() + .statusCode(200) + .body(is("Hello Sheldon")); + + } + + @Test + public void testPolling() throws InterruptedException { + + bindQueue(SpringRabbitmqResource.POLLING_QUEUE_NAME, EXCHANGE_POLLING, ROUTING_KEY_POLLING); + + //start thread with the poling consumer from exchange "polling", polling queue, routing "pollingKey", result is sent to polling direct + RestAssured.given() + .queryParam(SpringRabbitmqResource.QUERY_EXCHANGE, EXCHANGE_POLLING) + .queryParam(SpringRabbitmqResource.QUERY_ROUTING_KEY, ROUTING_KEY_POLLING) + .post("/spring-rabbitmq/startPolling"); + + // wait a little to demonstrate we can start poll before we have a msg on the queue + Thread.sleep(500); + + sendToExchange(EXCHANGE_POLLING, ROUTING_KEY_POLLING, "Sheldon"); + + //get result from direct (for pooling) with timeout + getFromDirect(SpringRabbitmqResource.DIRECT_POLLING, 1000) + .then() + .statusCode(200) + .body(is("Polling Hello Sheldon")); + + } + + private void sendToExchange(String exchange, String routingKey, String body) { + RestAssured.given() + .queryParam(SpringRabbitmqResource.QUERY_EXCHANGE, exchange) + .queryParam(SpringRabbitmqResource.QUERY_ROUTING_KEY, routingKey) + .body(body) + .post("/spring-rabbitmq/send"); + } + + private Response getFromDirect(String direct) { + return getFromDirect(direct, 0); + } + + private Response getFromDirect(String direct, int timeout) { + return RestAssured.given() + .queryParam(SpringRabbitmqResource.QUERY_DIRECT, direct) + .queryParam(SpringRabbitmqResource.QUERY_TIMEOUT, timeout) + .post("/spring-rabbitmq/getFromDirect"); + } + + private void bindQueue(String queue, String exchange, String routingKey) { + Queue q = new Queue(queue, false); + DirectExchange t = new DirectExchange(exchange); + AmqpAdmin admin = new RabbitAdmin(connectionFactory); + admin.declareQueue(q); + admin.declareExchange(t); + admin.declareBinding(BindingBuilder.bind(q).to(t).with(routingKey)); + } + + public void setConnectionFactory(ConnectionFactory connectionFactory) { + this.connectionFactory = connectionFactory; + } +} diff --git a/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTestResource.java b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTestResource.java new file mode 100644 index 0000000..95d7622 --- /dev/null +++ b/integration-tests/spring-rabbitmq/src/test/java/org/apache/camel/quarkus/component/spring/rabbitmq/it/SpringRabbitmqTestResource.java @@ -0,0 +1,78 @@ +/* + * 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.quarkus.component.spring.rabbitmq.it; + +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.util.CollectionHelper; +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.testcontainers.containers.RabbitMQContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +public class SpringRabbitmqTestResource implements QuarkusTestResourceLifecycleManager { + + private static final String RABBITMQ_IMAGE = "rabbitmq:3.7.25-management-alpine"; + private static final int RABBITMQ_PORT = 5672; + private static final String RABBITMQ_USERNAME = "guest"; + private static final String RABBITMQ_PASSWORD = "guest"; + + private RabbitMQContainer container; + + @Override + public Map<String, String> start() { + + try { + container = new RabbitMQContainer(RABBITMQ_IMAGE) + .withExposedPorts(RABBITMQ_PORT) + .waitingFor(Wait.forListeningPort()); + container.start(); + + return CollectionHelper.mapOf( + SpringRabbitmqResource.PARAMETER_PORT, container.getMappedPort(RABBITMQ_PORT).toString(), + SpringRabbitmqResource.PARAMETER_HOSTNAME, container.getHost(), + SpringRabbitmqResource.PARAMETER_USERNAME, RABBITMQ_USERNAME, + SpringRabbitmqResource.PARAMETER_PASSWORD, RABBITMQ_PASSWORD); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void inject(Object testInstance) { + if (testInstance instanceof SpringRabbitmqTest) { + SpringRabbitmqTest test = (SpringRabbitmqTest) testInstance; + + CachingConnectionFactory cf = new CachingConnectionFactory(); + cf.setUri(String.format("amqp://%s:%d", container.getHost(), container.getMappedPort(RABBITMQ_PORT))); + cf.setUsername(RABBITMQ_USERNAME); + cf.setPassword(RABBITMQ_PASSWORD); + + test.setConnectionFactory(cf); + } + } + + @Override + public void stop() { + try { + if (container != null) { + container.stop(); + } + } catch (Exception e) { + // Ignored + } + } +} diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 4e58f9a..6d3df20 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -1882,6 +1882,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-rabbitmq</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-sql</artifactId> <version>${camel.version}</version> <exclusions> @@ -4793,6 +4798,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-spring-rabbitmq-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-sql</artifactId> <version>${camel-quarkus.version}</version> </dependency> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index e11f229..579b2e4 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -121,6 +121,7 @@ messaging-networking1: - kafka - messaging - nats + - spring-rabbitmq - rabbitmq - ftp - graphql
