DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Robust Integration Solutions With Apache Camel and Spring Boot
  • Apache Camel Integration with Kafka
  • Quick Integration With IBM MQ Using Apache Camel
  • Integrating Google BigQuery With Amazon SageMaker

Trending

  • How Trustworthy Is Big Data?
  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • FIPS 140-3: The Security Standard That Protects Our Federal Data
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Apache Camel Integration With ActiveMQ

Apache Camel Integration With ActiveMQ

This article covers integration of Apache Camel with ActiveMQ.

By 
Vignesh Prabhu user avatar
Vignesh Prabhu
·
Feb. 25, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.3K Views

Join the DZone community and get the full member experience.

Join For Free

This article covers Apache Camel Integration with ActiveMQ.

Setup

Apache MQ Setup

We will launch Apache MQ as a Docker container. Run the below command to launch Apache MQ as a Docker container.

PowerShell
 




xxxxxxxxxx
1


 
1
docker run -p 61616:61616 -p 8161:8161 rmohr/activemq


Refer: https://hub.docker.com/r/rmohr/activemq

Open the ActiveMQ web console at http://localhost:8161. Click on Manage ActiveMQ broker and login using admin as the username and password when prompted for credentials. 

A screen like the below opens: 

Let's create two Spring Boot Camel microservices, camel-demo-a and camel-demo-b

camel-demo-a will publish the data to the ActiveMQ queue which will be consumed by camel-demo-b

In the pom.xml of both the microservices, add the below dependency:

XML
 




xxxxxxxxxx
1


 
1
<dependency>
2
    <groupId>org.apache.camel.springboot</groupId>
3
    <artifactId>camel-activemq-starter</artifactId>
4
    <version>3.8.0</version>
5
</dependency>


Configure the broker URL in the application.properties

Properties files
 




x


 
1
spring.activemq.broker-url=tcp://localhost:61616


Configuring the ActiveMQ Sender Route in camel-demo-a

The route is configured to read from the file and publish it to the ActiveMQ queue:

Java
 




xxxxxxxxxx
1
16


 
1
package com.vignesh.cameldemoa.routes.a;
2

          
3
import org.apache.camel.builder.RouteBuilder;
4
import org.springframework.stereotype.Component;
5

          
6
@Component
7
public class ActiveMQSenderRoute extends RouteBuilder {
8

          
9
    @Override
10
    public void configure() throws Exception {        
11

          
12
        from("file:files/input")
13
                .to("activemq:myqueue");
14
    }
15
}


Configuring the ActiveMQ Receiver Route in camel-demo-b

Let's assume that the sender route is publishing a JSON message, which we will unmarshall and use to perform some processing.

To the pom.xml file of the camel-demo-b application, add the below dependency: 

XML
 




xxxxxxxxxx
1


 
1
<dependency>
2
    <groupId>org.apache.camel.springboot</groupId>
3
    <artifactId>camel-jackson-starter</artifactId>
4
    <version>3.8.0</version>
5
</dependency>


Creating the Model Class

Java
 




xxxxxxxxxx
1
31


 
1
package com.vignesh.cameldemob.model;
2

          
3
public class Employee {
4
    private int id;
5
    private String name;
6

          
7
    public Employee() {
8
    }
9

          
10
    public Employee(int id, String name) {
11
        this.id = id;
12
        this.name = name;
13
    }
14

          
15
    public int getId() {
16
        return id;
17
    }
18

          
19
    public String getName() {
20
        return name;
21
    }
22

          
23
    @Override
24
    public String toString() {
25
        return "Employee{" +
26
                "id=" + id +
27
                ", name='" + name + '\'' +
28
                '}';
29
    }
30
}


The route is configured to consume the message from the ActiveMQ queue, so we'll unmarshal it using the Jackson JSON library and do some processing.  

Java
 




x
33


 
1
package com.vignesh.cameldemob.route.b;
2

          
3
import com.vignesh.cameldemob.model.Employee;
4
import org.apache.camel.builder.RouteBuilder;
5
import org.apache.camel.model.dataformat.JsonLibrary;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Component;
10

          
11
@Component
12
public class ActiveMQReceiverRoute extends RouteBuilder {
13

          
14
    @Autowired
15
    GetEmployee getEmployee;
16

          
17
    @Override
18
    public void configure() throws Exception {
19
        from("activemq:myqueue")
20
                .unmarshal().json(JsonLibrary.Jackson, Employee.class)
21
                .bean(getEmployee)
22
                .to("log:myloggingqueue");
23
    }
24
}
25

          
26
@Component
27
class GetEmployee{
28
    Logger logger= LoggerFactory.getLogger(GetEmployee.class);
29
    public void getData(Employee employee){
30
        logger.info("Emp data: "+employee.getId());
31
    }
32
}


Testing

Start the camel-demo-a application and place the JSON file in the input folder.

The file will be read and the message will be published to the ActiveMQ queue.

Start the camel-demo-b application. Observe that the route consumes the message from the queue and that it performs JSON unmarshalling as well as further processing.

Apache Camel Integration

Opinions expressed by DZone contributors are their own.

Related

  • Robust Integration Solutions With Apache Camel and Spring Boot
  • Apache Camel Integration with Kafka
  • Quick Integration With IBM MQ Using Apache Camel
  • Integrating Google BigQuery With Amazon SageMaker

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!