You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Andrea Cosentino <an...@gmail.com> on 2020/04/06 07:01:25 UTC
Re: [camel-examples] branch master updated: added camel-example-spring-boot-amqp
Ramu, please have a look at the git log, we are reverting these changes.
This needs more work to be done.
Il giorno lun 6 apr 2020 alle ore 08:58 <ra...@apache.org> ha scritto:
> This is an automated email from the ASF dual-hosted git repository.
>
> ramu12 pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/camel-examples.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
> new e513b96 added camel-example-spring-boot-amqp
> e513b96 is described below
>
> commit e513b96614e09de88bebf827251f700616923695
> Author: Kodanda Ramu Kakarla <kk...@kkakarla.pnq.csb>
> AuthorDate: Mon Apr 6 12:23:56 2020 +0530
>
> added camel-example-spring-boot-amqp
> ---
> .../camel-example-spring-boot-amqp/README.adoc | 36 ++++++
> examples/camel-example-spring-boot-amqp/pom.xml | 129
> +++++++++++++++++++++
> .../src/main/data/ReadMe.txt | 43 +++++++
> .../src/main/java/sample/camel/AmqpConfig.java | 86 ++++++++++++++
> .../java/sample/camel/SampleAmqApplication.java | 32 +++++
> .../sample/camel/SampleAutowiredAmqpRoute.java | 46 ++++++++
> .../src/main/resources/application.properties | 25 ++++
> .../sample/camel/SampleAmqApplicationTests.java | 43 +++++++
> 8 files changed, 440 insertions(+)
>
> diff --git a/examples/camel-example-spring-boot-amqp/README.adoc
> b/examples/camel-example-spring-boot-amqp/README.adoc
> new file mode 100644
> index 0000000..50fba31
> --- /dev/null
> +++ b/examples/camel-example-spring-boot-amqp/README.adoc
> @@ -0,0 +1,36 @@
> +== Camel Example Spring Boot and ActiveMQ AMQP
> +
> +This example shows how to work with a simple Apache Camel application
> using Spring Boot and Apache ActiveMQ.
> +
> +=== Preparing ActiveMQ brokers
> +
> +From Apache ActiveMQ you can download the broker as a `.zip` or `.tar.gz`
> file.
> +
> +Unzip/tar the archive, and start a terminal.
> +
> +Change directory to the unzipped directory and start the broker.
> +
> + bin/activemq console
> +
> +Which runs the broker in the foreground and logs to the console.
> +
> +=== How to run the example
> +
> +You can run this example using
> +
> + mvn spring-boot:run
> +
> +=== Using Camel components
> +
> +Apache Camel provides 200+ components which you can use to integrate and
> route messages between many systems
> +and data formats. To use any of these Camel components, add the component
> as a dependency to your project.
> +
> +=== Help and contributions
> +
> +If you hit any problem using Camel or have some feedback, then please
> +https://camel.apache.org/support.html[let us know].
> +
> +We also love contributors, so
> +https://camel.apache.org/contributing.html[get involved] :-)
> +
> +The Camel riders!
> diff --git a/examples/camel-example-spring-boot-amqp/pom.xml
> b/examples/camel-example-spring-boot-amqp/pom.xml
> new file mode 100644
> index 0000000..729d1e9
> --- /dev/null
> +++ b/examples/camel-example-spring-boot-amqp/pom.xml
> @@ -0,0 +1,129 @@
> +<?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.example</groupId>
> + <artifactId>examples</artifactId>
> + <version>3.2.0-SNAPSHOT</version>
> + </parent>
> +
> + <artifactId>camel-example-spring-boot-amqp</artifactId>
> + <name>Camel :: Example :: Spring Boot :: Amqp</name>
> + <description>An example showing how to work with Camel, ActiveMQ Amqp
> and Spring Boot</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.springboot</groupId>
> + <artifactId>camel-spring-boot-dependencies</artifactId>
> + <version>${project.version}</version>
> + <type>pom</type>
> + <scope>import</scope>
> + </dependency>
> + </dependencies>
> +
> + </dependencyManagement>
> +
> + <dependencies>
> +
> + <dependency>
> + <groupId>org.springframework.boot</groupId>
> + <artifactId>spring-boot-starter-web</artifactId>
> + <exclusions>
> + <exclusion>
> + <groupId>org.springframework.boot</groupId>
> + <artifactId>spring-boot-starter-tomcat</artifactId>
> + </exclusion>
> + </exclusions>
> + </dependency>
> + <dependency>
> + <groupId>org.springframework.boot</groupId>
> + <artifactId>spring-boot-starter-undertow</artifactId>
> + </dependency>
> +
> + <dependency>
> + <groupId>org.apache.camel.springboot</groupId>
> + <artifactId>camel-amqp-starter</artifactId>
> + </dependency>
> +
> + <!-- Camel -->
> + <dependency>
> + <groupId>org.apache.camel.springboot</groupId>
> + <artifactId>camel-spring-boot-starter</artifactId>
> + </dependency>
> +
> + <dependency>
> + <groupId>org.apache.camel</groupId>
> + <artifactId>camel-amqp</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>
> + </plugins>
> + </build>
> +</project>
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
> b/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
> new file mode 100644
> index 0000000..c384fbd
> --- /dev/null
> +++ b/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
> @@ -0,0 +1,43 @@
> +example project which connects to A-MQ 7 from Fuse 7, using remote A-MQ
> address
> +
> +There is the code, from that project, which instantiates component, and
> sends message
> +
> +public class CamelRoute extends RouteBuilder {
> +
> + @Override
> + public void configure() throws Exception {
> + JmsComponent component = createArtemisComponent();
> + getContext().addComponent("artemis", component);
> +
> +
> from("timer://foo?fixedRate=true&period=60000&repeatCount=2")
> + .setBody().constant("HELLO")
> + .to("artemis:queue:test")
> + .log("Sent --> ${body}")
> + ;
> + }
> +
> + private JmsComponent createArtemisComponent() {
> +
> + ActiveMQJMSConnectionFactory connectionFactory= new
> ActiveMQJMSConnectionFactory("tcp://localhost:61616");
> + connectionFactory.setUser("admin");
> + connectionFactory.setPassword("admin");
> +
> + JmsComponent component = new JmsComponent();
> + component.setConnectionFactory(connectionFactory);
> +
> + return component;
> + }
> +}
> +
> +Please see pom file, I don't specify pom versions, because they come in
> the BOM
> +
> + <dependency>
> + <groupId>org.apache.activemq</groupId>
> + <artifactId>artemis-jms-client</artifactId>
> + </dependency>
> + <dependency>
> + <groupId>org.apache.camel</groupId>
> + <artifactId>camel-jms</artifactId>
> + </dependency>
> +
> +
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
> new file mode 100644
> index 0000000..d981fbc
> --- /dev/null
> +++
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
> @@ -0,0 +1,86 @@
> +/*
> + * 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.beans.factory.annotation.Value;
> +import org.springframework.context.annotation.Bean;
> +import org.springframework.context.annotation.Configuration;
> +
> +@Configuration
> +public class AmqpConfig {
> +
> + @Value("${AMQP_HOST}")
> + private String amqpHost;
> + @Value("${AMQP_SERVICE_PORT}")
> + private String amqpPort;
> + @Value("${AMQP_SERVICE_USERNAME}")
> + private String userName;
> + @Value("${AMQP_SERVICE_PASSWORD}")
> + private String pass;
> + @Value("${AMQP_REMOTE_URI}")
> + private String remoteUri;
> +
> + public String getAmqpHost() {
> + return amqpHost;
> + }
> +
> + public void setAmqpHost(String amqpHost) {
> + this.amqpHost = amqpHost;
> + }
> +
> + public String getAmqpPort() {
> + return amqpPort;
> + }
> +
> + public void setAmqpPort(String amqpPort) {
> + this.amqpPort = amqpPort;
> + }
> +
> + public String getUserName() {
> + return userName;
> + }
> +
> + public void setUserName(String userName) {
> + this.userName = userName;
> + }
> +
> + public String getPass() {
> + return pass;
> + }
> +
> + public void setPass(String pass) {
> + this.pass = pass;
> + }
> +
> + public String getRemoteUri() {
> + return remoteUri;
> + }
> +
> + public void setRemoteUri(String remoteUri) {
> + this.remoteUri = remoteUri;
> + }
> +
> + @Bean
> + public org.apache.qpid.jms.JmsConnectionFactory
> amqpConnectionFactory() {
> + org.apache.qpid.jms.JmsConnectionFactory jmsConnectionFactory =
> new org.apache.qpid.jms.JmsConnectionFactory();
> + jmsConnectionFactory.setRemoteURI(remoteUri);
> + jmsConnectionFactory.setUsername(userName);
> + jmsConnectionFactory.setPassword(pass);
> + return jmsConnectionFactory;
> + }
> +
> +}
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
> new file mode 100644
> index 0000000..bd7b327
> --- /dev/null
> +++
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
> @@ -0,0 +1,32 @@
> +/*
> + * 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.EnableAutoConfiguration;
> +import org.springframework.boot.autoconfigure.SpringBootApplication;
> +
> +//CHECKSTYLE:OFF
> +@SpringBootApplication
> +@EnableAutoConfiguration
> +public class SampleAmqApplication {
> +
> + public static void main(String[] args) {
> + SpringApplication.run(SampleAmqApplication.class, args);
> + }
> +}
> +// CHECKSTYLE:ON
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
> new file mode 100644
> index 0000000..671643d
> --- /dev/null
> +++
> b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
> @@ -0,0 +1,46 @@
> +/*
> + * 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.apache.qpid.jms.JmsConnectionFactory;
> +import org.springframework.beans.factory.annotation.Autowired;
> +import org.springframework.context.annotation.Bean;
> +import org.springframework.stereotype.Component;
> +
> +@Component
> +public class SampleAutowiredAmqpRoute extends RouteBuilder {
> +
> + @Autowired JmsConnectionFactory amqpConnectionFactory;
> + @Bean
> + public org.apache.camel.component.amqp.AMQPComponent amqpConnection()
> {
> + org.apache.camel.component.amqp.AMQPComponent amqp = new
> org.apache.camel.component.amqp.AMQPComponent();
> + amqp.setConnectionFactory(amqpConnectionFactory);
> + return amqp;
> + }
> +
> + @Override
> + public void configure() throws Exception {
> + from("file:src/main/data?noop=true")
> + .to("amqp:queue:SCIENCEQUEUE");
> +
> + /*from("timer:bar")
> + .setBody(constant("Hello from Camel"))
> + .to("amqp:queue:SCIENCEQUEUE");*/
> + }
> +
> +}
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
> b/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
> new file mode 100644
> index 0000000..e70b0d5
> --- /dev/null
> +++
> b/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
> @@ -0,0 +1,25 @@
> +##
> ---------------------------------------------------------------------------
> +## 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.
> +##
> ---------------------------------------------------------------------------
> +
> +#You can use this property to override the default autowired broker-url
> +
> +camel.springboot.main-run-controller = true
> +AMQP_REMOTE_URI=amqp://localhost:5672
> +AMQP_HOST=localhost
> +AMQP_SERVICE_PORT=5672
> +AMQP_SERVICE_USERNAME=admin
> +AMQP_SERVICE_PASSWORD=admin
> diff --git
> a/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
> b/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
> new file mode 100644
> index 0000000..4243bda
> --- /dev/null
> +++
> b/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
> @@ -0,0 +1,43 @@
> +/*
> + * 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 java.util.concurrent.TimeUnit;
> +
> +import org.apache.camel.CamelContext;
> +import org.apache.camel.builder.NotifyBuilder;
> +import org.apache.camel.test.spring.CamelSpringBootRunner;
> +import org.junit.Ignore;
> +import org.junit.runner.RunWith;
> +import org.springframework.beans.factory.annotation.Autowired;
> +import org.springframework.boot.test.context.SpringBootTest;
> +
> +import static org.junit.Assert.assertTrue;
> +
> +@RunWith(CamelSpringBootRunner.class)
> +@SpringBootTest(classes = SampleAmqApplication.class)
> +public class SampleAmqApplicationTests {
> + @Autowired
> + private CamelContext camelContext;
> +
> + @Ignore("Requires a running activemq broker")
> + public void shouldProduceMessages() throws Exception {
> + NotifyBuilder notify = new
> NotifyBuilder(camelContext).whenDone(1).create();
> +
> + assertTrue(notify.matches(10, TimeUnit.SECONDS));
> + }
> +}
>
>