37
PASS THE MESSAGE with RabbitMQ

Pass the message with RabbitMQ

Embed Size (px)

Citation preview

Page 1: Pass the message with RabbitMQ

PASS THE MESSAGE with RabbitMQ

Page 2: Pass the message with RabbitMQ

DONE THIS?

JobId Address Message Status

1 [email protected] Hello Anders, Lorem Ipsum

Sent

2 [email protected]

Hello Anders, Lorem Ipsum

Processing

3 [email protected] Hello Anders, Lorem Ipsum

Waiting

EmailSender

SELECT TOP 1 * FROM EmailSender WHERE Status = ’Waiting’

UPDATE EmailSender SET Status = ’Processing’ WHERE JobId = 3

Page 3: Pass the message with RabbitMQ

OR THIS?

ProductId Amount LastUpdate

1 4711.50 2015-05-26T13:37:42.4711

2 1337.40 2015-05-26T13:37:43.1234

3 42.50 2015-05-26T13:38:05.4561

Prices

SELECT * FROM Prices

WHERE LastUpdate > ’2015-05-20T04:40:09.123’

Page 4: Pass the message with RabbitMQ

ME, ME, ME

Solution Designer at Thomas Cook

Organizer of Swenug

Co-founder of Swetugg

Tweeter at @CodingInsomnia

Page 5: Pass the message with RabbitMQ

TOPICS

Queues and Messages

RabbitMQ

Messaging Patterns

Samples

Page 6: Pass the message with RabbitMQ

MESSAGE QUEUE

FIFO - First In - First Out

Producers creates a message

Consumers process messages

Asynchronous communication

Page 7: Pass the message with RabbitMQ

MESSAGE QUEUE

Producer Consumer

Page 8: Pass the message with RabbitMQ

RABBITMQ

Message Broker

Erlang runtime

Cross-Platform

Page 9: Pass the message with RabbitMQ

MESSAGES IN RABBITMQ

Byte Arrays

Usually JSON or XML

Size limited by server memory

Headers

Page 10: Pass the message with RabbitMQ

SETTING UP RABBITMQ

C:\>choco install RabbitMQ

C:\>rabbitmq-plugins enable rabbitmq_management

Page 11: Pass the message with RabbitMQ

USING RABBITMQ FROM .NET PS C:\> Install-Package RabbitMQ.Client

Page 12: Pass the message with RabbitMQ

CODE Hello World

Page 13: Pass the message with RabbitMQ

MESSAGING PATTERNS

Work queues

Publish-Subscribe

Request-Reply

Message Routing

Page 14: Pass the message with RabbitMQ

WORK QUEUES

One or more Producers

One or more Consumers

A single, shared queue

Page 15: Pass the message with RabbitMQ

Consumer

Producer

WORK QUEUES

Producer

Consumer

Page 16: Pass the message with RabbitMQ

CODE Work Queues

Page 17: Pass the message with RabbitMQ

PUBLISH-SUBSCRIBE

One or more Publishers

Any number of Subscribers

Copy of the message to each Subscriber

Page 18: Pass the message with RabbitMQ

EXCHANGES

Messages are always published to an Exchange

Queues bind to Exchanges

Page 19: Pass the message with RabbitMQ

FANOUT EXCHANGE

Subscriber

Subscriber

Subscriber

Publisher FanoutExchang

e

Page 20: Pass the message with RabbitMQ

CODE Publish-Subscribe

Page 21: Pass the message with RabbitMQ

ROUTING

More control over what message ends up where

Direct Exchange

Topic Exchange

Headers Exchange

Page 22: Pass the message with RabbitMQ

DIRECT EXCHANGE

Bind to a Direct Exchange with a RoutingKey

Messages published to the exchange are routed to queues with a matching key

Page 23: Pass the message with RabbitMQ

DIRECT EXCHANGE

Subscriber

Subscriber

Subscriber

Publisher DirectExchang

e

a a

b

a

aa

b

bb

b

Page 24: Pass the message with RabbitMQ

TOPIC EXCHANGE

Bind to a Topic Exchange with a RoutingKey pattern”order.book”, ”order.dvd”, ”order.dvd.payment”

List of words delimited by dots

WildcardsA * matches any single word (”order.*”)A # matches zero or more words (”order.#”)

Page 25: Pass the message with RabbitMQ

TOPIC EXCHANGE

Subscriber

Subscriber

Subscriber

Publisher TopicExchang

e

a.1 *.1

b.#

a.1

a.1a.1b.

1b.1b.1

Page 26: Pass the message with RabbitMQ

MICROSERVICES

Tiny building blocks

Message-oriented

Need new functionality? Build a new service.

Need to refactor? Throw the old service away.

Page 27: Pass the message with RabbitMQ

MICRO SERVICES

Message Bus (Topic Exchange)

Web

Email handlerContact handler

query: anders

@ljusberg.se

query

contact: 1

contact

response: Anders

Ljusberg

response

Page 28: Pass the message with RabbitMQ

MICRO SERVICES

Message Bus (Topic Exchange)

Web

Email handlerContact handler

query: @CodingIns

query

contact

response

Twitter handler

response: Anders

Ljusberg

query

contact: 1

Page 29: Pass the message with RabbitMQ

CODE Microservices

Page 30: Pass the message with RabbitMQ

MESSAGE TTL

How long is this message valid?

Per queueRemoved immidately

Per messageRemoved when at front of queue

Page 31: Pass the message with RabbitMQ

DEAD LETTER EXCHANGE

Failed messages can be routed to a Dead Letter Exchange

Any type of Exchange

Rejected messages

Messages that have timed out

Queue length exceeded

Page 32: Pass the message with RabbitMQ

DEAD LETTER EXCHANGE

ProducerConsume

r

Exchange

Error handler

Dead Letter Exchange

Page 33: Pass the message with RabbitMQ

CODE Dead Letters

Page 34: Pass the message with RabbitMQ

THINGS I SKIPPED

Request-Reply

Headers Exchange

Page 35: Pass the message with RabbitMQ

SUMMARY

Message Queuing is good

Microservices is.. well.. interesting..

Page 36: Pass the message with RabbitMQ

THERE’S MUCH MORE…

FrameworksMassTransitEasyNetQ

High AvailabilityFederationClusteringLoad Balancing

Priority Queues

Message Scheduling

Page 37: Pass the message with RabbitMQ

QUESTIONS?

@CodingInsomnia

[email protected]

http://coding-insomnia.com

https://github.com/andlju

http://www.swenug.se

http://swetugg.se

Other stuff:

http://rabbitmq.com

http://erlang.org

https://chocolatey.org

http://masstransit-project.com

http://easynetq.com