Welcome to Spring AMQP ActiveMQ Tutorial. Earlier we looked into installing Apache ActiveMQ server. Today we will create a spring application to work with ActiveMQ JMS queues.

Spring AMQP ActiveMQ Tutorial

The Spring AMQP ActiveMQ Tutorial is divided into following sections.

  • Introduction
  • Spring AMQP Tag Libraries
  • Steps to Develop and Test Spring AMQP with ActiveMQ
  • Benefits and Drawbacks of Spring AMQP with ActiveMQ
  • Create JMS Queues in ActiveMQ Server
  • Create Spring AMQP Configuration for ActiveMQ

Introduction

We have already discussed some “Spring AMQP Basics” Theoretically and “How to install and setup ActiveMQ Server” in my previous posts. Please refer them in the following:

In this post and my next coming post, we are going to develop a Spring AMQP ActiveMQ Messaging application using Queues that is One-to-One Messaging Application. Let us start it now.

Initially I thought of delivering one post for this whole example. However, after preparing whole steps I feel that its too lengthy post. So its divided into two posts. In this post, we are going to discuss some Apache ActiveMQ Basics, then how to configure our application queues then do some Spring Framework AMQP and ActiveMQ API XML Configuration. In my next post, we will develop actual Java programs and test it.

Please click here “Spring AMQP ActiveMQ Messaging Example” to access part-2 post.

Spring AMQP Tag Libraries

Spring Framework has provided two kinds of AMQP tag library to work with the following AMQP Servers:

    • RabbitMQ AMQP Tag Library

Spring RabbitMQ AMQP Tag Library is used to develop Messaging applications for RabbitMQ Server using Spring AMQP API and Spring RabbitMQ API.

Spring RabbitMQ AMQP Tag Library is defined in “spring-rabbit.xsd” file.

    • ActiveMQ AMQP Tag Library

Spring ActiveMQ AMQP Tag Library is used to develop Messaging applications for Apache ActiveMQ Server using Spring AMQP API and Apache ActiveMQ API.

Spring RabbitMQ AMQP Tag Library is defined in “activemq-core.xsd” file.

Steps to Develop and Test Spring AMQP with ActiveMQ

In this section, I will just list out what are all the steps we need to do to develop and test a Spring AMQP Messaging application with Apache ActiveMQ Server. We will discuss discuss these steps in depth with example in coming sections and coming post.

Please follow these steps to develop and test Spring AMQP Messaging application with Apache ActiveMQ Server.

  • Install Apache ActiveMQ Server (refer ActiveMQ section)
  • Create a Mavenized Java project in Eclipse
  • Create Spring AMQP Configuration for ActiveMQ
  • Create JMS Queues in ActiveMQ Server
  • Develop Spring AMQP Messaging Application With ActiveMQ
  • Test Spring AMQP Messaging Application With ActiveMQ

These are the brief steps to develop and test Spring AMQP Messaging application with Apache ActiveMQ Server. If you don’t understand them well, no worries. We will discuss these steps one by one in coming sections.

Benefits and Drawbacks of Spring AMQP with ActiveMQ

In this section, we will discuss: Compare to “Spring AMQP With RabbitMQ Server” combination, what are the benefits and drawbacks of “Spring AMQP With ActiveMQ Server” combination

“Spring AMQP With ActiveMQ” combination have the following benefits:

  • Apache ActiveMQ Server supports XA Transactions very well.
  • We can easily embedded Apache ActiveMQ MQ Broker into Java applications.
  • It is very easy to integrate “Spring AMQP With ActiveMQ Application” with Apache Camel.

Even though “Spring AMQP With ActiveMQ” combination have many benefits, it has one major drawback:

  • ActiveMQ needs more memory to maintain the application.

Create JMS Queues in ActiveMQ Server

    • Create JMS Queue by using new ActiveMQ Admin console
    • Click on “+Create” button, provide details and click on “Create Queue” button
    • spring_activemq_setup
    • Click on “Browse” button to view messages
    • spring_activemq_setup

Create Spring AMQP Configuration for ActiveMQ

Here URL contains protocol, host name and port number.By default, this application needs tcp protocol. Host name is localhost. We are using default port number 61616.

  • Configure destination (Here we are using queue)

  • Declare Producer Connection Factory by using Spring JMS API’s SingleConnectionFactory

  • Declare Consumer Connection Factory by using Spring JMS API’s SingleConnectionFactory

NOTE:-
Both Producer and Consumer should refer to the previously created JMS Factory object as shown in the above Spring AMQP XML Configuration.

  • Configure Spring JmsTemplate for JMS Producer to send messages to Destination

  • Configure JMS Listener to consume messages

  • Complete Spring Configuration file:

That’s it all about Spring XML Configuration to develop a Spring AMQP ActiveMQ Messaging Example. Please head over to Spring ActiveMQ Example for the second part of this tutorial.

By admin

Leave a Reply

%d bloggers like this: