SlideShare a Scribd company logo
Spring RabbitMQ
Martin Toshev
Who am I
Software consultant (CoffeeCupConsulting)
BG JUG board member (http://jug.bg)
OpenJDK and Oracle RDBMS enthusiast
Twitter: @martin_fmi
2
3
Work in progress …
4
Agenda
• Messaging Basics
• RabbitMQ Overview
• Spring RabbitMQ
5
Messaging
• Messaging provides a mechanism for loosely-coupled
integration of systems
• The central unit of processing in a message is a message
which typically contains a body and a header
6
Use cases
• Log aggregation between systems
• Event propagation between systems
• Offloading long-running tasks to worker nodes
• many others …
7
Messaging protocols
• Messaging solutions implement different protocols for
transferring of messages such as AMQP, XMPP, MQTT,
STOMP and others
• The variety of protocols imply vendor lock-in
8
Messaging protocols comparison
AMQP MQTT XMPP STOMP
goal replacement of proprietary
protocols
messaging for resource-
constrained devices
instant messaging,
adopted for wider use
Message-oriented
middleware
format binary binary XML-based text-based
API divided into classes
(> 40 methods in RabbitMQ)
simple (5 basic operations with
2-3 packet types for each)
different XML items
with multiple types
~ 10 basic
commands
reliability publisher/subscriber
acknowledgements,
transactions
acknowledgements Acknowledgments and
resumptions (XEP-198)
Subscriber
acknowledgements
and transactions
security SASL, TLS/SSL no built-in TLS/SSL,
header authentication
SASL, TLS/SSL depending on
message broker
extensibility extension points none extensible depending on
message broker
9
Messaging brokers
• A variety of messaging brokers can be a choice for
applications …
10
Common characteristics
• secure message transfer, authentication and
authorization of messaging endpoints
• message routing and persistence
• broker subscriptions
11
RabbitMQ
• An open source message broker written in Erlang
• Implements the AMQP Protocol (Advanced Message
Queueing Protocol)
• Has a pluggable architecture and provides extension for
other protocols such as HTTP, STOMP and MQTT
12
RabbitMQ users
• JP Morgan (financial operations)
• Nasa (nebula computing)
• Google (event processing)
• Soundcloud (dashboard updates)
• Nokia (real-time traffic maps)
13
AMQP
• AMQP is a binary protocol that aims to standardize
middleware communication
• Derives its origins from the financial industry
• Defines multiple connection channels inside a single TCP
connection
14
AMQP characteristics
• The AMQP protocol defines:
– exchanges – the message broker endpoints that receive messages
– queues – the message broker endpoints that store messages from exchanges
and are used by subscribers for retrieval of messages
– bindings – rules that bind exchanges and queues
• The AMQP protocol is programmable – which means that
the above entities can be created/modified/deleted by
applications
15
Message handling
• Each message can be published with a routing key
• Each binding between an exchange and a queue has a
binding key
• Routing of messages is determined based on matching
between the routing and binding keys
16
Message routing
• Different types of messaging patterns are implemented
by means of different types of exchanges
• RabbitMQ provides the following types of exchanges:
– direct/default
– fanout
– topic
– headers
17
Default exchange
Publisher
Subscriber
Subscriber
Subscriber
Publisher
chat
log
general
error
warning
exchange=“”
key=“general”
payload=“XYZ”
(AMQP
default)
(AMQP default) is a system exchange
default exchange: suitable for point-to-point
communication between endpoints
18
Direct exchange
Publisher
Subscriber
Subscriber
Subscriber
Publisher
chat
log
general
error
warning
b_general
exchange=“chat”
key=“b_general”
payload=“XYZ”
(AMQP
default)
chat is defined as a direct exchange upon creation
direct exchange: suitable for point-to-point
communication between endpoints
19
Fanout exchange
Publisher
Subscriber
Subscriber
Subscriber
Publisher
chat
log
general
error
warning
exchange=“log”
key=“”
payload=“XYZ”
(AMQP
default)
log is defined as a fanout exchange upon creation
fanout exchange: suitable for broadcast type
of communication between endpoints
20
Topic exchange
Publisher
Subscriber
Subscriber
Subscriber
Publisher
chat
log
general
error
warn.server
exchange=“log”
key=“warning.#”
payload=“XYZ”
(AMQP
default)
log is defined as a topic exchange upon creation
warn.client
warning.server
warning.client
topic exchange: suitable for multicast type of
communication between endpoints
21
RabbitMQ clustering
• Default clustering mechanism provides scalability in
terms of queues rather than high availability
• Mirrored queues are an extension to the default
clustering mechanism that can be used to establish high
availability at the broker level
22
RabbitMQ Overview
(demo)
23
Spring RabbitMQ
• The Spring Framework provides support for RabbitMQ
by means of:
– The Spring AMQP framework
– The Spring Integration framework
– The Spring XD framework
24
Spring AMQP
• Provides RabbitMQ utilities such as:
– the RabbitAdmin class for automatically declaring queues, exchanges and
bindings
– Listener containers for asynchronous processing of inbound messages
– the RabbitTemplate class for sending and receiving messages
25
Spring AMQP usage
• Utilities of the Spring AMQP framework can be used
either directly in Java or preconfigured in the Spring
configuration
26
RabbitAdmin
(plain Java)
CachingConnectionFactory factory = new
CachingConnectionFactory("localhost");
Queue queue = new Queue("sample-queue");
TopicExchange exchange =
new TopicExchange("sample-topic-exchange");
RabbitAdmin admin = new RabbitAdmin(factory);
admin.declareQueue(queue);
admin.declareExchange(exchange);
admin.declareBinding(BindingBuilder.bind(queue).to(exchange)
.with("sample-key"));
factory.destroy();
27
Container listener
(plain Java)
CachingConnectionFactory factory =
new CachingConnectionFactory(
"localhost");
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(factory);
Object listener = new Object() {
public void handleMessage(String message) { … }};
MessageListenerAdapter adapter = new
MessageListenerAdapter(listener);
container.setMessageListener(adapter);
container.setQueueNames("sample-queue");
container.start();
28
RabbitTemplate
(plain Java)
CachingConnectionFactory factory =
new CachingConnectionFactory("localhost");
RabbitTemplate template =
new RabbitTemplate(factory);
template.convertAndSend("", "sample-queue",
"sample-queue test message!");
29
Spring-based configuration
• All of the above examples can be configured using Spring
configuration
• Cleaner and decouples RabbitMQ configuration for the
business logic
30
RabbitTemplate
(Spring configuration)
<rabbit:connection-factory
id="connectionFactory"
host="localhost" />
<rabbit:template id="amqpTemplate"
connection-factory="connectionFactory"
exchange=""
routing-key="sample-queue-spring"/>
31
Container listener
(Spring configuration)
<rabbit:listener-container
connection-factory="connectionFactory">
<rabbit:listener ref="springListener"
method="receiveMessage"
queue-names="sample-queue-spring" />
</rabbit:listener-container>
<bean id="springListener"
class=“ua.org.javaday.rabbitmq.spring.ListenerSpringExample"/>
32
Container listener
(Spring configuration)
public class ListenerSpringExample {
public void receiveMessage(String message) {
System.out.println("Message received: " +
message);
}
}
33
Container listener
(Spring annotations)
public class ListenerSpringExample {
@RabbitListener(queues = "sample-queue-spring")
public void receiveMessage(String message) {
System.out.println("Message received: " +
message);
}
}
34
RabbitAdmin
(Spring configuration)
<rabbit:admin id="amqpAdmin"
connection-factory="connectionFactory" />
35
Spring Boot
• If you don’t want to use xml-based configuration you can
use Spring Boot …
36
Spring Boot
@SpringBootApplication
public class AppConfiguration {
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory =
new CachingConnectionFactory("localhost");
return connectionFactory;
}
@Bean
public AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory());
}
}
37
Spring Integration AMQP
• The Spring Integration Framework provides:
– Inbound-channel-adapter for reading messages from a
queue
– outbound-channel-adapter for sending messages to an
exchange
38
Spring Integration AMQP
• The Spring Integration Framework provides:
– Inbound-gateway for request-reply communication at the
publisher
– outbound-gateway for request-reply communication at
the receiver
39
Spring Integration AMQP scenario
• Message replication without a RabbitMQ extension:
test-channel
test-
destination-
queue queue
(AMQP
default)
test-queue
queue
Inbound
channel
adapter
outbound
channel
adapter
Spring Integration instance RabbitMQ instanceRabbitMQ instance
40
Spring Integration AMQP scenario
<rabbit:connection-factory
id="connectionFactory"
host="localhost" />
<channel id="test-channel" />
<rabbit:queue name="test-queue" />
<rabbit:queue name="test-destination-queue" />
<rabbit:template id="amqpTemplate"
connection-factory="connectionFactory"
exchange=""
routing-key="test-queue" />
41
Spring Integration AMQP scenario
<amqp:inbound-channel-adapter
channel="test-channel"
queue-names="test-queue"
connection-factory="connectionFactory" />
<amqp:outbound-channel-adapter
channel="test-channel"
exchange-name=""
routing-key="test-destination-queue"
amqp-template="amqpTemplate" />
42
Yet another scenario
milk distributor app
online shop
(milk, bread, apples, rabbits …)
bread distributor app
apples distributor app
rabbits distributor app
customer
order processing system
Implementation
milk-queue
(AMQP
default)
RabbitMQ instance
Spring Integration instance
44
apple-queuetest
channel
milk-adapter
bread-queue
rabbit-queue
order
producer
order
router
milk
channel
bread-adapter
break
channel
apple-adapter
apple
channel
rabbit-adapterrabbit
channel
Spring RabbitMQ
(demo)
45
Summary
• The Spring Framework provides convenient utilities and
adapters for integrating with RabbitMQ
• Favor them over the RabbitMQ Java library in
Spring-based applications
46
Thank you !
Q&A
47
demos: https://github.com/martinfmi/spring_rabbitmq_samples
References
48
AMQP 0.9.1 specification
https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf
AMQP list of users
http://www.amqp.org/about/examples
RabbitMQ documentation
http://www.rabbitmq.com/documentation.html
References
49
Choosing Your Messaging Protocol: AMQP, MQTT, or STOMP
http://blogs.vmware.com/vfabric/2013/02/choosing-your-
messaging-protocol-amqp-mqtt-or-stomp.html
Spring AMQP reference
http://docs.spring.io/spring-amqp/reference/html/
Spring Integration AMQP
http://docs.spring.io/spring-integration/reference/html/amqp.html

More Related Content

PPTX
The RabbitMQ Message Broker
PDF
Introduction to AMQP Messaging with RabbitMQ
PPTX
Spring Boot and REST API
ODP
Introduction To RabbitMQ
PPTX
19 08-22 introduction to activeMQ
PPT
RabbitMQ.ppt
PDF
Lecture 3: Servlets - Session Management
PDF
Spring Framework - AOP
The RabbitMQ Message Broker
Introduction to AMQP Messaging with RabbitMQ
Spring Boot and REST API
Introduction To RabbitMQ
19 08-22 introduction to activeMQ
RabbitMQ.ppt
Lecture 3: Servlets - Session Management
Spring Framework - AOP

What's hot (20)

PDF
MicroCPH - Managing data consistency in a microservice architecture using Sagas
PDF
IBM MQ Basics
PPTX
Replicacion de Mezcla
PPT
Applet and graphics programming
PDF
Java servlets
PDF
[@NaukriEngineering] Messaging Queues
PPT
Network programming in Java
PPSX
Modificateurs d'accès en java
PPTX
Introduction to Node js
PPTX
Spring security
PPTX
Introduction à spring boot
PPTX
webworkers
PPTX
Rabbit MQ introduction
PPTX
Introducing type script
PPTX
Hébergement Web
PPTX
OWASP ZAP Workshop for QA Testers
PPTX
PPTX
RabbitMQ and AMQP with .net client library
MicroCPH - Managing data consistency in a microservice architecture using Sagas
IBM MQ Basics
Replicacion de Mezcla
Applet and graphics programming
Java servlets
[@NaukriEngineering] Messaging Queues
Network programming in Java
Modificateurs d'accès en java
Introduction to Node js
Spring security
Introduction à spring boot
webworkers
Rabbit MQ introduction
Introducing type script
Hébergement Web
OWASP ZAP Workshop for QA Testers
RabbitMQ and AMQP with .net client library
Ad

Viewers also liked (20)

PPTX
Spring RabbitMQ
PDF
Рецепты RabbitMQ
PPTX
Building a Docker v1.12 Swarm cluster on ARM
PPTX
Down to Stack Traces, up from Heap Dumps
PDF
Understanding the mysteries of the CSS property value syntax
PPTX
The "Why", "What" and "How" of Microservices
PPTX
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
PPTX
Security Аrchitecture of Тhe Java Platform
PPTX
Writing Stored Procedures with Oracle Database 12c
PPTX
Writing Java Stored Procedures in Oracle 12c
PPTX
Writing Stored Procedures in Oracle RDBMS
PPTX
Modular Java
PPTX
RxJS vs RxJava: Intro
PDF
KDB database (EPAM tech talks, Sofia, April, 2015)
PPTX
Developing rich multimedia applications with Kurento: a tutorial for Java Dev...
PPTX
Security Architecture of the Java platform
PPTX
JVM++: The Graal VM
PDF
Eclipse plug in development
PPTX
elasticRTC -- how to have your own WebRTC cloud scaling to be billions in min...
PPTX
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Spring RabbitMQ
Рецепты RabbitMQ
Building a Docker v1.12 Swarm cluster on ARM
Down to Stack Traces, up from Heap Dumps
Understanding the mysteries of the CSS property value syntax
The "Why", "What" and "How" of Microservices
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Security Аrchitecture of Тhe Java Platform
Writing Stored Procedures with Oracle Database 12c
Writing Java Stored Procedures in Oracle 12c
Writing Stored Procedures in Oracle RDBMS
Modular Java
RxJS vs RxJava: Intro
KDB database (EPAM tech talks, Sofia, April, 2015)
Developing rich multimedia applications with Kurento: a tutorial for Java Dev...
Security Architecture of the Java platform
JVM++: The Graal VM
Eclipse plug in development
elasticRTC -- how to have your own WebRTC cloud scaling to be billions in min...
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Ad

Similar to Spring RabbitMQ (20)

ODP
Red Hat Open Day JBoss Fuse
PDF
The Future of Messaging: RabbitMQ and AMQP
PDF
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
PDF
Messaging with RabbitMQ and AMQP
PDF
EIP In Practice
PDF
quickguide-einnovator-3-rabbitmq
PPTX
Commication Framework in OpenStack
PPTX
Mule with rabbit mq
PPTX
Mule rabbitmq
PPTX
Mule with rabbit mq
PPTX
Mule with rabbit mq
PPTX
Mule with rabbit mq
PPTX
Mule with rabbitmq
PPTX
Rabbit mq in mule
PPTX
Mule with rabbit mq
PPTX
Rabbit Mq in Mule
PPTX
Mule with rabbit mq
PDF
Spring integration
PPTX
Mule rabbit mq
PPTX
Mule with rabbitmq
Red Hat Open Day JBoss Fuse
The Future of Messaging: RabbitMQ and AMQP
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Messaging with RabbitMQ and AMQP
EIP In Practice
quickguide-einnovator-3-rabbitmq
Commication Framework in OpenStack
Mule with rabbit mq
Mule rabbitmq
Mule with rabbit mq
Mule with rabbit mq
Mule with rabbit mq
Mule with rabbitmq
Rabbit mq in mule
Mule with rabbit mq
Rabbit Mq in Mule
Mule with rabbit mq
Spring integration
Mule rabbit mq
Mule with rabbitmq

More from Martin Toshev (13)

PPTX
Building highly scalable data pipelines with Apache Spark
PPTX
Big data processing with Apache Spark and Oracle Database
PPT
Jdk 10 sneak peek
PPT
Semantic Technology In Oracle Database 12c
PPTX
Practical security In a modular world
PPT
Java 9 Security Enhancements in Practice
PPTX
Java 9 sneak peek
PPTX
Oracle Database 12c Attack Vectors
PDF
Concurrency Utilities in Java 8
PPTX
java2days 2014: Attacking JavaEE Application Servers
PPTX
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
PPTX
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
PPTX
New Features in JDK 8
Building highly scalable data pipelines with Apache Spark
Big data processing with Apache Spark and Oracle Database
Jdk 10 sneak peek
Semantic Technology In Oracle Database 12c
Practical security In a modular world
Java 9 Security Enhancements in Practice
Java 9 sneak peek
Oracle Database 12c Attack Vectors
Concurrency Utilities in Java 8
java2days 2014: Attacking JavaEE Application Servers
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
New Features in JDK 8

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Monthly Chronicles - July 2025
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
Modernizing your data center with Dell and AMD
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

Spring RabbitMQ

Editor's Notes

  • #15: * In the financial industry processing of large volumes of financial data between different systems is a classic use case of messaging * The AMQP protocol defines multiple connection channels inside a single TCP connection in order to remove the overhead of opening a large number of TCP connections to the message broker * Mention about RabbitMQ Users
  • #23: RabbitMQ provides clustering support that allows new RabbitMQ nodes to be added on the fly Clustering by default does not guarantee that message loss may not occur