Spring ActiveMQ Example (Part 2)

This is the second part in the Spring ActiveMQ example tutorial. Please head over to the first part at Spring AMQP ActiveMQ Tutorial.

Spring ActiveMQ Example

We will have following sections in this Spring ActiveMQ Example post.

  • Introduction
  • Develop Spring AMQP Messaging Application With ActiveMQ
  • Develop Test client for Spring AMQP ActiveMQ Messaging Application
  • Test Spring AMQP Messaging Application With 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, we are going to develop a Spring AMQP ActiveMQ Messaging application. Let us start it now.

Develop Spring AMQP Messaging Application With ActiveMQ

Let us start developing a Spring AMQP ActiveMQ Messaging application using Maven, Eclipse IDE and ActiveMQ Server. It is same for all other Java IDEs.

Please do the following the steps one by one:

  • Develop Spring ActiveMQ AMQP Publisher program

  • Develop JMS Asynchronous JMS Consumer by using Spring JMS APIs MDPs.

  • Final pom.xml file

Develop Test client for Spring AMQP ActiveMQ Messaging Application

  • Develop a Test application

NOTE:- As this Unit test name is ActiveMQJmsMessageListenerTest, then @ContextConfiguration annotation searches for ActiveMQJmsMessageListenerTest-context.xml file in same package structure.

  • Final Project Structure

Here we can see our Spring AMQP ActiveMQ Messaging application’s final Eclipse project structure.

spring_activemq_project_structure

Test Spring AMQP Messaging Application With ActiveMQ

In this section, we will test our Spring AMQP ActiveMQ Messaging application using our Test client developed in the previous section.

  • Observe above Test program. We are using asserting concept to test the message count

If both published and consumed messages are NOT equal then the below does not throw AssertError.

  • Run the Unit and see the successful message.

Right click on the Test program and run it as Junit test.

  • To see message in ActiveMQ Admin console, please comment listener configuration in XML file

And run test class again and observe ActiveMQ Admin console for 10 messages:

spring_activemq_queuemsgs

  • And run test class again and observe ActiveMQ Admin console for 10 messages:

Unit test will fail as we don’t consume any messages. But that is fine as we need see messages in ActiveMQ Queue.

That’s it all about developing Spring AMQP ActiveMQ Messaging Example.

By admin

Leave a Reply

%d bloggers like this: