Filed Under: JMS

We will look into Spring AMQP today.

Spring AMQP

Spring AMQP is the Spring implementation of AMQP-based messaging solutions. Spring AMQP provides us a “template” as a high-level abstraction for sending and receiving messages. We will look into following topics in this spring AMQP. tutorial.

  1. What is AMQP?
  2. Why we need AMQP?
  3. Difference between JMS and AMQP
  4. How Spring AMQP works?
  5. Spring AMQP Modules

What is AMQP?

We have already discussed some JMS concepts and examples in my previous posts. In this post, we are going to discuss AMQP protocol and Spring AMQP Messaging.

AMQP stands for Advanced Message Queuing Protocol. AMQP is an open standard protocol for implementing MOMs (Message Oriented Middleware).

Why we need AMQP?

We have JMS API to develop Enterprise Messaging systems but why we need another Messaging standard.

The main drawback or limitation of JMS API is interoperability that means we can develop Messaging systems that will work only in Java-based applications. It does not support other languages.

AMQP solves the JMS API problem. The major advantage of AMQP is that it supports interoperability between heterogeneous platforms and messaging brokers. We can develop our Messaging systems in any language (Java, C++, C#, Ruby etc.) and in any operating system; still, they can communicate with each other by using AMQP based message brokers.

Difference between JMS and AMQP

In this section, we will discuss about what are the differences between JMS and AMQP protocols.

  1. Interoperability
  2. JMS Application works in any OS environment, but it supports only Java platform. If we want to develop the below system architecture by using JMS API then all those systems should be developed by using Java language only.

    But if we use AMQP standard to develop the same system, then we can develop those systems in any language that means System-1(JAVA), System-2(C#), System-3(Ruby) and System-4(C++).

    amqp protocol

    JMS API is specific for Java Platform only, but AMQP supports many technologies.

  3. Messaging Models
  4. As we have already discussed, JMS API supports two kinds of messaging models: P2P(Peer-to-Peer) Model and PUB/SUB (Publisher/Subscriber) Model.

    AMQP supports five different Messaging models (or Exchange types)

    1. Direct Exchange
    2. Fanout Exchange
    3. Topic Exchange
    4. Headers Exchange
    5. System Exchange
  5. Message Structure
  6. JMS Message is divided into 3 parts: Header, Properties, and Body.
    AMQP Message is divided into 4 parts: Header, Properties, Body, and Footer.

  7. Message Types
  8. JMS API supports 5 types of messages as part of the Body section, but AMQP supports only one type of message – Binary (bytes) message.

How Spring AMQP works?

Spring Framework provides Spring AMQP API to integrate AMQP Message brokers with Spring applications to develop Enterprise Messaging Systems.

In AMQP Messaging systems, Message Publisher sends messages to Exchange. Publisher does not know which queue is configured to this Exchange and which Consumer is associated with this Queue.

While configuring Exchange, we will map it to one or more Queues by specifying some routing key.

AMQP Consumer is connected to Queue and listening to messages with some routing key.

When Publisher sends a message into Exchange, then Exchange uses this routing key and send those messages to associated Queue. When the Queue receives messages, then associated Consumer receives those messages automatically.

spring amqp

For example, we have implemented our AMQP Messaging system by following above architecture.

If Publisher sends a message with Route key = 1, then this message is routed to Queue1, then to Consumer1.

If Publisher sends a message with Route key = 2, then this message is routed to Queue2, then to Consumer2.

NOTE: Most popular AMQP protocol implemented Message brokers or JMS Servers are:

  1. Apache Active MQ server
  2. Spring Rabbit MQ server

Spring AMQP Modules

Spring Framework provides two set of APIs to deal with AMQP protocol servers. Spring AMQP Projects are located at the following website:

https://spring.io/projects/spring-amqp

  1. Spring RabbitMQ AMQP API
  2. Spring RabbitMQ AMQP API is used to implement messaging applications with Spring Rabbit MQ server. This API is developed in two Spring modules:

    • spring-amqp:
    • It is base abstraction for AMQP Protocol implementation.

    • spring-rabbit:
    • It is the RabbitMQ implementation.

  3. Spring ActiveMQ AMQP API
  4. This API is used to implement messaging applications with Apache Active MQ server. This API uses Spring AMQP abstraction module with ActiveMQ API:

    • spring-amqp:
    • It is base abstraction for AMQP Protocol implementation.

    • activemq-spring:
    • It is the ActiveMQ implementation.

NOTE:

  • Both Spring AMQP and Spring RabbitMQ Modules are from Pivotal Team (Spring Framework). RabbitMQ servers is also from Pivotal Team.
  • ActiveMQ Server is from Apache Software Foundation. Apache ActiveMQ has released an API to support Spring Framework that is activemq-spring (It’s not from Pivotal Team).

That’s it all about Spring AMQP Messaging.

Further Reading: Spring RabbitMQ, Apache ActiveMQ

Comments

  1. Binh Thanh Nguyen says:

    Thanks, nice post

  2. Hi Rambabu,

    Thank you for the effort of narrating in simple terms.

    Could you also explained how AMQP exchange types are different from each other and when should we use them?

    Regards,
    Himansu

  3. Deepak Nirala says:

    There will be modification in below
    Spring RabbitMQ AMQP API

    One API is used to to implement Messaging applications with Apache Active MQ server. This API is developed in two Spring modules:

    — here instead of Apache Active MQ server it should be Spring Rabbit MQ server

    Spring ActiveMQ AMQP API
    Another API is used to implement Messaging applications with Spring Rabbit MQ server.This API uses Spring AMQP abstraction module with ActiveMQ API:

    — here instead of Spring Rabbit MQ server it should be Apache Active MQ server

    1. Rambabu says:

      Hi Deepak, Thanks for finding typo errors. Updated them and also added some more text at the end of the post.

      Thanks.
      Ram

  4. Abdelghani says:

    Hello,
    Bref and excellent article.
    Thanks.

    Abdelghani
    Senior Software developer

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages