grails + messaging with amqp/ rabbitmq · pdf filegrails + messaging with amqp/ rabbitmq peter...
TRANSCRIPT
![Page 1: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/1.jpg)
SpringOne 2GX 2010. All rights reserved. Do not distribute without permission.
Chicago, October 19 - 22, 2010
Grails + messaging with AMQP/RabbitMQ
Peter Ledbrook - SpringSource
Friday, 22 October 2010
![Page 2: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/2.jpg)
2
A history of messaging
Friday, 22 October 2010
![Page 3: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/3.jpg)
A history of messaging
Friday, 22 October 2010
![Page 4: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/4.jpg)
A history of messaging
4
Friday, 22 October 2010
![Page 5: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/5.jpg)
Java messaging - JMS
5
• Java API• Synchronous and asynchronous messaging• Point-to-point and broadcast
– P2P via Queues– Broadcast via Topics
• No standard for communication between client and broker
Friday, 22 October 2010
![Page 6: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/6.jpg)
JMS Queues
6
Producer
Broker
Queue Consumer
Friday, 22 October 2010
![Page 7: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/7.jpg)
JMS Topics
7
Producer
Broker
Topic
Consumer
Consumer
Consumer
Friday, 22 October 2010
![Page 8: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/8.jpg)
The challenger - AMQP
8
• Advanced Message Queuing Protocol• Wire-level protocol
– Any type of client– Client-broker communication standardised
• Synchronous and asynchronous messaging• Point-to-point, broadcast, and more
– Single, flexible model• Simple management part of the protocol
– Create exchanges and queues
Friday, 22 October 2010
![Page 9: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/9.jpg)
Basic structure
9
Producer
Broker
Exchange
Consumer
Consumer
Consumer
Queue
QueueConsumer
Friday, 22 October 2010
![Page 10: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/10.jpg)
Basic structure
9
Producer
Broker
Exchange
Consumer
Consumer
Consumer
Queue
QueueConsumer
Exchange: accepts and routes messages from producer
Friday, 22 October 2010
![Page 11: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/11.jpg)
Basic structure
9
Producer
Broker
Exchange
Consumer
Consumer
Consumer
Queue
QueueConsumer
Exchange: accepts and routes messages from producer
Queue: a FIFO queue of messages - each message can only go to one consumer
Friday, 22 October 2010
![Page 12: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/12.jpg)
Basic structure
9
Producer
Broker
Exchange
Consumer
Consumer
Consumer
Queue
QueueConsumer
Exchange: accepts and routes messages from producer
Binding: rule for routing messages to associated queue
Queue: a FIFO queue of messages - each message can only go to one consumer
Friday, 22 October 2010
![Page 13: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/13.jpg)
Exhanges
10
• Only producers talk to the exchange directly• Message routing depends on
– Exchange type– Message’s ‘routing key’, e.g. “stocks.nasdaq.vmw”– Binding between exchange and queue
• Routing and binding keys are typically strings– Allow for filtering - similar to JMS selectors
Friday, 22 October 2010
![Page 14: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/14.jpg)
Exhange types
11
• Fanout– Messages go to all bound queues– Routing and binding keys are ignored
• Direct– Messages only go to queues with a binding key that exactly
matches the routing key– Typically routing key is the queue name
• Topic– Like Direct exchange but binding key can have wildcards– ‘#’ like regex ‘*’, ‘*’ like regex ‘?’
• Headers– Routing based on message headers
Friday, 22 October 2010
![Page 15: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/15.jpg)
Example: JMS-like Queue
12
Producer
Broker
DirectExchange ConsumermyQueue
Friday, 22 October 2010
![Page 16: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/16.jpg)
Example: JMS-like Queue
12
Producer
Broker
DirectExchange ConsumermyQueue
routing-key = myQueue
Friday, 22 October 2010
![Page 17: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/17.jpg)
Example: JMS-like Queue
12
Producer
Broker
DirectExchange ConsumermyQueue
routing-key = myQueue
binding = myQueue
Friday, 22 October 2010
![Page 18: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/18.jpg)
Example: JMS-like Topic
13
Producer
Broker
FanoutExchange
ConsumerQueue
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 19: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/19.jpg)
Example: JMS-like Topic
13
Producer
Broker
FanoutExchange
ConsumerQueue
Routing key not specified
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 20: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/20.jpg)
Example: JMS-like Topic
13
Producer
Broker
FanoutExchange
ConsumerQueue
Routing key not specified
Binding not specified
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 21: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/21.jpg)
Example: broadcast with filtering
14
Producer
Broker
TopicExchange
ConsumerQueue
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 22: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/22.jpg)
Example: broadcast with filtering
14
Producer
Broker
TopicExchange
ConsumerQueue
routing-key = shares.nyse.vmw
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 23: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/23.jpg)
Example: broadcast with filtering
14
Producer
Broker
TopicExchange
ConsumerQueue
routing-key = shares.nyse.vmw
binding = shares.#
ConsumerQueue
ConsumerQueue
Friday, 22 October 2010
![Page 24: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/24.jpg)
Example: broadcast with filtering
14
Producer
Broker
TopicExchange
ConsumerQueue
routing-key = shares.nyse.vmw
ConsumerQueue
ConsumerQueue
binding = shares.*
Friday, 22 October 2010
![Page 25: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/25.jpg)
Example: broadcast with filtering
14
Producer
Broker
TopicExchange
ConsumerQueue
routing-key = shares.nyse.vmw
ConsumerQueue
ConsumerQueue
binding = shares.nyse.vmw
Friday, 22 October 2010
![Page 26: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/26.jpg)
Example: RPC
15
Producer
Broker
DirectExchange
ConsumermyQueue
replyQ
Friday, 22 October 2010
![Page 27: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/27.jpg)
Example: RPC
15
Producer
Broker
DirectExchange
ConsumermyQueue
replyQrouting-key = myQueuereply-to = replyQ
Friday, 22 October 2010
![Page 28: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/28.jpg)
Example: RPC
15
Producer
Broker
DirectExchange
ConsumermyQueue
binding = myQueue
replyQrouting-key = myQueuereply-to = replyQ
Friday, 22 October 2010
![Page 29: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/29.jpg)
Example: RPC
15
Producer
Broker
DirectExchange
ConsumermyQueue
replyQ
routing-key = replyQ
Friday, 22 October 2010
![Page 30: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/30.jpg)
Example: RPC
15
Producer
Broker
DirectExchange
ConsumermyQueue
replyQ
binding = replyQ
routing-key = replyQ
Friday, 22 October 2010
![Page 31: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/31.jpg)
Example: work distribution
16
Producer
Broker
DirectExchange
Consumer
ConsumerQueue
Consumer
Friday, 22 October 2010
![Page 32: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/32.jpg)
Example: work distribution
16
Producer
Broker
DirectExchange
Consumer
routing-key = some.task
ConsumerQueue
Consumer
Friday, 22 October 2010
![Page 33: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/33.jpg)
Example: work distribution
16
Producer
Broker
DirectExchange
Consumer
routing-key = some.task
binding = some.task
ConsumerQueue
Consumer
Friday, 22 October 2010
![Page 34: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/34.jpg)
Messages
17
• Headers– routing-key– reply-to– content-type, etc.
• Custom properties• Body
– Byte data– Producer and consumer must agree on the format of the content– ... or use content-type header– AMQP does not define a meaning for content-type!
Friday, 22 October 2010
![Page 35: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/35.jpg)
Queue and exchange properties
18
• Durable– Survives a broker restart– Applies to exchanges and queues
• Auto delete– Exchange will be deleted when all its bindings are gone– Queue will be deleted when all consumers are gone
• Exclusive– Only the owner can read messages from the queue– Doesn’t apply to exchanges
Friday, 22 October 2010
![Page 36: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/36.jpg)
The Grails integration
19
• RabbitMQ plugin• Declare exchanges and queues• Configure services as queue consumers
– Simple static properties• Dynamic method for sending AMQP messages
Friday, 22 October 2010
![Page 37: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/37.jpg)
Consuming messages
20
class ListenerService { // Declare name of queue to listen to static rabbitQueue = "msgs"
void handleMessage(msg) { // Do something with the message }}
class AnotherListenerService { // Subscribe to a topic exchange static rabbitSubscribe = "sharesExchange"
void handleMessage(msg) { // Do something with the message }}
Friday, 22 October 2010
![Page 38: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/38.jpg)
Consuming messages
20
class ListenerService { // Declare name of queue to listen to static rabbitQueue = "msgs"
void handleMessage(msg) { // Do something with the message }}
class AnotherListenerService { // Subscribe to a topic exchange static rabbitSubscribe = "sharesExchange"
void handleMessage(msg) { // Do something with the message }}
class AnotherListenerService { // Subscribe to a topic exchange static rabbitSubscribe = [ name: "myEx", routingKey: "shares.#" ]
void handleMessage(msg) { // Do something with the message }}
Friday, 22 October 2010
![Page 39: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/39.jpg)
class PublisherService {
def notify() { rabbitSend "msgs", "app.event", "The event details" }}
Sending messages
21
Friday, 22 October 2010
![Page 40: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/40.jpg)
class PublisherService {
def notify() { rabbitSend "msgs", "app.event", "The event details" }}
Sending messages
21
Routing key
Exchange name(optional) Message body
Friday, 22 October 2010
![Page 41: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/41.jpg)
class PublisherService {
def notify() { rabbitSend "msgs", "app.event", "The event details" }}
Sending messages
21
class PublisherService {
def notify(String itemName) { rabbitSend "msgs", "app.event", [event: "publish", item: itemName ] }}
Friday, 22 October 2010
![Page 42: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/42.jpg)
Declaring exchanges and queues
22
// Config.groovyrabbitmq { connectionfactory { ... }
queues = { msgs durable: false, autoDelete: true exchange name: "shares", type: topic, durable: true, { allShares durable: true, autoDelete: false, binding: 'shares.#' } }}
Friday, 22 October 2010
![Page 43: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/43.jpg)
Declaring exchanges and queues
22
// Config.groovyrabbitmq { connectionfactory { ... }
queues = { msgs durable: false, autoDelete: true exchange name: "shares", type: topic, durable: true, { allShares durable: true, autoDelete: false, binding: 'shares.#' } }}
Standalone queue (msgs) - bound to default direct exchange
Topic exchange (shares)
Queue (allShares) bound to exchange (shares) with routing key ('shares.#')
Friday, 22 October 2010
![Page 44: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/44.jpg)
A word about message content
23
• In the broker, it’s just byte data• Plugin interprets data based on content-type header
– Spring AMQP SimpleMessageConverter– String ➝ text/plain; charset=utf-8– Serializable ➝ application/x-java-serialized-object– Otherwise, just byte[]
• Producers & consumers typically agree on format• Not all clients set the content-type!• You still have to agree on format even if you use JSON or
XML message content
Friday, 22 October 2010
![Page 45: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/45.jpg)
SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Chicago, October 19 - 22, 2010
Demo
Friday, 22 October 2010
![Page 46: Grails + messaging with AMQP/ RabbitMQ · PDF fileGrails + messaging with AMQP/ RabbitMQ Peter Ledbrook - SpringSource Friday, 22 October 2010. 2 A history of messaging ... The Grails](https://reader031.vdocuments.site/reader031/viewer/2022021817/5a83e7b37f8b9a9d308f1e49/html5/thumbnails/46.jpg)
SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Chicago, October 19 - 22, 2010
Q&A
Friday, 22 October 2010