In this post we will try to understand the basic concepts of Rabbit MQ, components involved in transmission of messages, basic api's required in spring-amqp and so on...
spring-amqp is the base abstraction and spring-rabbit is the RabbitMQ implementation
There are mainly 3 important basic classes we need to know before starting the development:
RabbitMQ: RabbitMQ
is open source message broker software that implements the Advanced Message Queuing Protocol (AMQP).
AMQP: The
Advanced Message Queuing Protocol (AMQP) is an open standard application layer
protocol for sending and receiving messages between distributed systems.
Message Brokers:
Message brokers receive messages from the publishers and route them to
consumers.
Bindings: Relationship between the exchange and the queue is called
binding
Rabbit MQ working:
- Messages are published to the exchange
- Exchange distributes the message copies to queues using binding rules
- Consumer application receives the messages. In AMQP model there are two ways for applications to consume
- Have message delivered to the consumer application(push API)
- Fetch messages as needed(pull API)
Exchange types: Exchanges
take a message and route it into zero or more queues. The routing algorithm used
depends on the exchange type and bindings
There are 4 types of exchanges:
- Direct exchange: A direct exchange delivers messages to queues based on the message routing key.
- Fanout exchange: A fanout exchange routes messages to all of the queues that are bound to it and the routing key is ignored.
- Topic exchange: Topic exchanges route messages to one or many queues based on matching between a message routing key and the pattern that was used to bind a queue to an exchange.
- Headers exchange: A headers exchange is designed for routing on multiple attributes that are more easily expressed as message headers than a routing key.
Message
acknowledgements
Consumer applications may fail to process the messages due
various reasons like network issue or system failure etc.
AMQP specification proposes two choices for this:
- Delete the message from the queue, when broker sends the message to the application (automatic acknowledgement model: using either basic.deliver or basic.get-ok AMQP method)
- Delete the message from the queue, when the application sends back the acknowledgement (explicit acknowledgment model: using basic.ack AMQP method)
Important Spring AMQP API’s for basic operations:
spring-amqp is the base abstraction and spring-rabbit is the RabbitMQ implementation
There are mainly 3 important basic classes we need to know before starting the development:
- CachingConnectionFactory: Used for creating connections
- RabbitAdmin: Used for declaring exchanges, queues, bindings
- RabbitTemplate: Specifies basic set of AMQP operations
In the next post, we will see how to configure fanout exchange using spring amqp and exchange messages between producer and consumer applications

No comments:
Post a Comment