Giter Site home page Giter Site logo

spring-boot-camel-amq's Introduction

Spring-Boot, Camel and AMQ QuickStart

This quickstart demonstrates how to connect a Spring-Boot application AMQ Broker and use JMS messaging between two Camel routes using Kubernetes or OpenShift.

In this example we will use two containers, one container to run as an AMQ Broker instance, and another as a client to the broker, where the Camel routes are running.

This quickstart requires AMQ Broker to have been deployed and running first. To install AMQ Broker into OpenShift or Kubernetes follow documentation.

Quickstart uses the standard address space and requires standard authentication. For address space and queue definition standard-small-queue, standard_unlimited plans are used, therefore make sure you have also installed example plans, roles and standard authentication service.

The application utilizes the Spring @ImportResource annotation to load a Camel Context definition via a src/main/resources/spring/camel-context.xml file on the classpath.

Important
This quickstart can run in 2 modes: standalone on your machine and on Kubernetes / OpenShift Cluster. Quickstart requires Java 8 or Java 11 (fuse-java-openshift-jdk11-rhel8 image is used to build in Java 11).

Deployment options

You can run this quickstart in the following modes:

  • Kubernetes / Single-node OpenShift cluster

  • Standalone on your machine

The most effective way to run this quickstart is to deploy and run the project on OpenShift.

For more details about running this quickstart on a single-node OpenShift cluster, CI/CD deployments, as well as the rest of the runtime, see the Spring Boot Runtime Guide.

Running the Quickstart on a single-node Kubernetes/OpenShift cluster

Important
You need to run this example on Container Development Kit 3.3 or OpenShift 3.7. Both of these products have suitable Fuse images pre-installed. If you run it in an environment where those images are not preinstalled follow the steps described in Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images.

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-amq) :

    $ cd my_openshift/spring-boot-camel-amq
  4. Before running the quickstart, you need to configure AMQ Broker (to create user and queue - both as an admin). Run the following commands to apply configuration files:

    $ oc login -u system:admin
    $ oc apply -f src/main/resources/k8s
  5. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift
  6. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-amq has started up.

  7. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-amq application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-amq-NUMBER_OF_DEPLOYMENT?tab=details.

  8. Switch to tab Logs and then see the messages sent by Camel.

Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Configure Red Hat Container Registry authentication (if it is not configured). Follow documentation.

  4. Import base images in your newly created project (MY_PROJECT_NAME):

    $ oc import-image fuse-java-openshift:1.13 --from=registry.redhat.io/fuse7/fuse-java-openshift-rhel8:1.13 --confirm
  5. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-amq) :

    $ cd my_openshift/spring-boot-camel-amq
  6. Before running the quickstart, you need to configure AMQ Broker (to create user and queue - both as an admin). Run the following commands to apply configuration files:

    $ oc login -u system:admin
    $ oc apply -f src/main/resources/k8s
  7. Wait until address space is ready:

    $ oc get addressspace karaf-camel-amq -o jsonpath={.status.isReady}
  8. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift -Djkube.generator.fromMode=istag -Djkube.generator.from=MY_PROJECT_NAME/fuse-java-openshift:1.13
  9. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-amq has started up.

  10. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-amq application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-amq-NUMBER_OF_DEPLOYMENT?tab=details.

  11. Switch to tab Logs and then see the messages sent by Camel:

...
2021-03-05 10:12:54,502 | INFO  | ile://work/jms/input | file-to-jms-route                | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Receiving order order166.xml
2021-03-05 10:12:54,526 | INFO  | umer[incomingOrders] | jms-cbr-route                    | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Sending order order166.xml to the UK
2021-03-05 10:12:54,527 | INFO  | umer[incomingOrders] | jms-cbr-route                    | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Done processing order166.xml
2021-03-05 10:12:59,527 | INFO  | ile://work/jms/input | file-to-jms-route                | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Receiving order order167.xml
2021-03-05 10:12:59,556 | INFO  | umer[incomingOrders] | jms-cbr-route                    | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Sending order order167.xml to the UK
2021-03-05 10:12:59,557 | INFO  | umer[incomingOrders] | jms-cbr-route                    | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Done processing order167.xml
2021-03-05 10:13:04,558 | INFO  | ile://work/jms/input | file-to-jms-route                | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Receiving order order168.xml
2021-03-05 10:13:04,568 | INFO  | umer[incomingOrders] | jms-cbr-route                    | 126 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | Sending order order168.xml to the US
...

Running the quickstart standalone on your machine

To run this quickstart as a standalone project on your local machine:

  1. You need to have a running instance of AMQ Broker with messaging user user1:test and queue incomingOrders.

    You can use AMQ Broker instance from previous steps. You need to configure the src/main/resources/application.properties file in order to use the correct remote instance of AMQ Broker.

    Get remote url of AMQ Broker instance by running the following command:

    $ oc get addressspace spring-boot-camel-amq -o jsonpath={.status.endpointStatuses[?(@.name==\'messaging\')].externalHost}

    Fill this value into src/main/resources/application.properties instead of FILL_ME.

  2. Download the project and extract the archive on your local filesystem.

  3. Build the project:

    $ cd PROJECT_DIR
    $ mvn clean package
  4. Run the service:

    $ mvn spring-boot:run
  5. See the messages sent by Camel.

spring-boot-camel-amq's People

Contributors

aldettinger avatar apupier avatar astefanutti avatar chirino avatar cunningt avatar dhirajsb avatar ffang avatar fusesource-ci avatar grgrzybek avatar jamesnetherton avatar janstey avatar jiriondrusek avatar jstrachan avatar lburgazzoli avatar luigidemasi avatar mcarlett avatar mmelko avatar nicolaferraro avatar oscerd avatar rawlingsj avatar rhuss avatar rnetuka avatar valdar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-boot-camel-amq's Issues

Camel AMQ client tries to access ActiveMQ using the loopback address when deployed on Openshift

Camel AMQ client tries to access ActiveMQ using the loopback address when deployed on Openshift and not using the Service address --> https://github.com/fabric8-quickstarts/spring-boot-camel-amq/blob/master/src/main/resources/application.properties#L28

mvn clean fabric8:deploy -Dfabric8.mode=kubernetes
oc get pods
oc logs spring-boot-camel-amq-1-vi21e
-->
17:41:03.618 [Camel (camel) thread #10 - timer://order] WARN  o.a.c.component.timer.TimerConsumer - Error processing exchange. Exchange[ID-spring-boot-camel-amq-1-vi21e-35898-1478194763984-0-64]. Caused by: [org.springframework.jms.UncategorizedJmsException - Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://127.0.0.1:61616. Reason: java.net.ConnectException: Connection refused]
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://127.0.0.1:61616. Reason: java.net.ConnectException: Connection refused
        at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
        at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
        at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:487)
        at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:469)
        at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:414)
        at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:368)
        at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:154)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192)
        at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)

Question on AMQ configuration

I see that you have used XML configuration, do you have any configuration specific to Spring Boot where you can leverage Spring Boot's ActiveMQ configurations to be used in Camel Routes? Additionally, do you have any examples for the Camel Routes using Java DSL?
I am trying to do the same and have run into an issue. Here is the question on stackoverflow. Would you be able to provide some guidance?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.