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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building an Image Classification Pipeline With Apache Camel and Deep Java Library (DJL)
  • Building a Sentiment Analysis Pipeline With Apache Camel and Deep Java Library (DJL)
  • Robust Integration Solutions With Apache Camel and Spring Boot
  • Powering LLMs With Apache Camel and LangChain4j

Trending

  • GenAI Security Gateway: An End-to-End Architecture
  • Spring AI on Local LLMs
  • LangChainGo vs Genkit Go: Where Genkit Shines
  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Connecting Apache ActiveMQ With Apache Camel

Connecting Apache ActiveMQ With Apache Camel

This quick guide will help you connect Apache Camel and Apache ActiveMQ so you can both read and write messages between them.

By 
Jitendra Bafna
·
Dec. 25, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
32.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

ActiveMQ (or all Message Oriented Middleware (MOM) in general) implementations are designed for the purpose of sending messages between two applications or two components inside one application. It is the most popular and powerful open source messaging and Integration Patterns server.

Installing Active MQ on Windows

  • Download ActiveMQ

  • After the download is complete, extract the files to a user-defined folder.

Run ActiveMQ

  • Open the Windows command prompt.

  • Use the following command to change the current directory to the ActiveMQ installation directory.

cd <active_mq_directory>/bin


Image title

  • Run command activemq on command prompt.

Image title

Browse ActiveMQ and Creating Queues

  • Use the URL http://127.0.0.1:8161/ to browse ActiveMQ. The initial username is admin and the password is admin.

  • Click on Queue, give a Queuename (e.g. testQueue), and click on Create.

Image title

Connecting ActiveMQ With Apache Camel

POM dependency:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>com.learncamel</groupId>
    <artifactId>learncamel-activemq2db</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

    <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.19.2</version>
    </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-sql</artifactId>
            <version>2.19.2</version>
        </dependency>
    <!-- camel-jms dependency -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>2.19.2</version>
    </dependency>

    <!-- Apache Active MQ Jars -->

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <version>5.14.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-client</artifactId>
        <version>5.14.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-pool</artifactId>
        <version>5.14.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>5.14.5</version>
    </dependency>

    <!-- Logging Jars -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.12</version>
    </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test</artifactId>
            <version>2.19.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>


Building the Camel route to read messages from ActiveMQ:

package com.learncamel.route.jms;

import org.apache.camel.builder.RouteBuilder;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
public class JmsReadRoute extends RouteBuilder {
    public void configure() throws Exception {
        from("activemq:queue:testQueue")
                .to("log:?level=INFO&showBody=true")
                .to("direct:readQueue");
    }
}


Building the Camel route to write messages to ActiveMQ:

package com.learncamel.route.jms;

import org.apache.camel.builder.RouteBuilder;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
public class JmsWriteRoute extends RouteBuilder {
    public void configure() throws Exception {
        from("direct:writeQueue")
                .to("log:?level=INFO&showBody=true")
                .to("activemq:queue:testQueue");
    }
}


Now you know how to write and read messages to/from Apache ActiveMQ.

Apache Camel Apache ActiveMQ

Opinions expressed by DZone contributors are their own.

Related

  • Building an Image Classification Pipeline With Apache Camel and Deep Java Library (DJL)
  • Building a Sentiment Analysis Pipeline With Apache Camel and Deep Java Library (DJL)
  • Robust Integration Solutions With Apache Camel and Spring Boot
  • Powering LLMs With Apache Camel and LangChain4j

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook