20
Addressing Messaging Challenges Using Spring and RabbitMQ © 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission. Gary Russell, Staff Engineer, SpringSource; @gprussell

Russell spring one2gx_messaging_india

Embed Size (px)

Citation preview

Page 1: Russell spring one2gx_messaging_india

Addressing Messaging Challenges Using Spring and RabbitMQ

© 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Gary Russell, Staff Engineer, SpringSource; @gprussell

Page 2: Russell spring one2gx_messaging_india

Addressing Messaging Challenges

•  Modern Application Trends •  Modularize with Spring Integration •  Distribute with AMQP •  Analyze with Hadoop

2

Page 3: Russell spring one2gx_messaging_india

Place Order

Fulfill Order

Manage Inventory

Schedule Delivery

If any component is unavailable within this synchronous flow, all in-flight messages will be affected, regardless of what

component they are currently in -- and since state is maintained across the components, the system can be complex to reset

X X

X X

X X

X X

X

An exception occurred,

please resend

Synchronous Architecture is Brittle

3

Page 4: Russell spring one2gx_messaging_india

In this asynchronous flow: •  all state is kept in the simple messages being passed •  each stateless component interacts only with the broker cloud •  if a component is lost, only the in-flight messages within that

component must be re-delivered •  components can be quickly provisioned on-demand

I have an Order

I can fulfill part of that

Order

I’ll schedule delivery of that

order

I can fulfill part of that

Order Your order will be delivered next Tuesday

The status of your order is

Asynchronous Architecture Rules the Web

4

Page 5: Russell spring one2gx_messaging_india

Modern approaches to messaging embrace the unpredictable,

dynamic, and transient nature of the web

Traditional approaches to messaging imply predictable,

static interaction between well-known end-points

Modern Applications Need Modern Messaging

5

Page 6: Russell spring one2gx_messaging_india

Modularize with Spring Integration

Page 7: Russell spring one2gx_messaging_india

•  At the core, an embedded Message Bus –  Inspired by Gregor Hohpe and Bobby Woolf's Enterprise

Integration Patterns (2003) –  Runs within any Spring ApplicationContext –  All components are Spring-managed objects

•  Also, an Application Integration Framework –  Connects to other systems via adapters –  Unidirectional Channel Adapters –  Bidirectional Messaging Gateways

What is Spring Integration?

7

Page 8: Russell spring one2gx_messaging_india

cafe

orders drinks

coldDrinks

hotDrinks

preparedDrinks deliveries

CafeDemoApp

Spring Integration Cafe

8

Page 9: Russell spring one2gx_messaging_india

Café

http

Spring Integration Café – Simple HTTP Deployment

9

Page 10: Russell spring one2gx_messaging_india

Distribute with AMQP

10

Page 11: Russell spring one2gx_messaging_india

A  Protocol,  not  an  API  •  A  defined  set  of  messaging  

capabili2es  called  the  AMQ  model  

•  A  network  wire-­‐level  protocol,  AMQP   On  commodity  hardware  

•  10-­‐25  thousand  messages  per  second  is  rou@ne  *  

•  The  NIC  is  usually  the  boFleneck  

 *  Non-­‐persistent  messages  

Why AMQP?

11

Page 12: Russell spring one2gx_messaging_india

AMQP  security  •  Brokers  support  separate  

virtual  hosts  •  Three  levels  of  permissions  •  AMQP  over  SSL  is  supported  

Designed  to  scale  horizontally  •  Dozens  of  clustered  brokers  

are  common  

Why AMQP?

12

Page 13: Russell spring one2gx_messaging_india

new.order

queue

M3 M1 M2 new.order binding

new.order routing key

AMQP Architecture

13

Page 14: Russell spring one2gx_messaging_india

café NA deliveries

queue

café deliveries

queue

M3 M1 M2

M3 M1 M2

café WW deliveries

queue

M3 M1 M2

AMQP Architecture

14

Page 15: Russell spring one2gx_messaging_india

hot_drinks

queue

cold_drinks

queue

1 2

2

3

1

drink.cold

Message Routing Keys:

1.  drink.hot

2.  drink.cold

3.  drink.warm

all_drinks

queue

AMQP Architecture

15

Page 16: Russell spring one2gx_messaging_india

Spring-AMQP

•  AMQP core abstraction plus RabbitMQ implementation (built on rabbit client libraries)

•  Higher level patterns for clients: admin, producers and consumers –  RabbitAdmin – declare exchanges, queues, bindings –  RabbitTemplate – convenience methods for send and receive –  MessageListenerContainer – POJO message handler, asynchronous

•  Spring Integration support

http://www.springsource.org/spring-amqp

16

Page 17: Russell spring one2gx_messaging_india

Spring-AMQP – What’s New (1.1.x)

•  Support for HA Queues –  Broker Failover

•  Publisher Confirms –  Callback when the message is secured in the broker

•  Publisher Returns –  Callback if message cannot be deposited in at least one queue

•  Explicit Reply Queue –  Avoids creation of temporary queue for request/reply scenarios

•  Dead Letter Exchange/Queue Support

17

Page 18: Russell spring one2gx_messaging_india

Demo – Distributing the Spring Integration Café Demo with AMQP

Page 19: Russell spring one2gx_messaging_india

Spring Integration Café – Distributed Deployment with AMQP

19

amqp

Café Ops Café Storefront

http

amqp

Page 20: Russell spring one2gx_messaging_india

Spring Integration Café – Distributed Deployment with Hadoop

CRM Data Marts ERP

hdfs

map reduce

unstructured event data

structured information EDW

20

amqp

Café Ops Café Storefront

http

amqp