Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

Messaging Patterns

An alternative approach to modeling with ESB’s

Jimmy P
@pjimmy
mail@thejimmyp.com
http://www.blog.thejimmyp.com
Outline
 Some Context
 Some Problems
 Intro to Messaging Systems
 Some Solutions
 And The Focus
 Some Patterns
Platform Temporal

Spatial
Afferent

Efferent

It’s mainly about coupling

Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent

• AKA interoperability

• Most RPC and other common messaging technologies are platform

• dependent in painful places


Platform Temporal

Spatial
Afferent

Efferent

• When A calls B synchronously B’s processing time affects A

A B
A Calls B

A Blocks While B Processes


B Processes

B Returns
Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent
• Where are the components physically?

• Is there multiple instances, and where are they?

• How do I decide which of multiple logically identical components


I should send my message to?

• What happens if the only physical instance I know of is down?


Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent

• Afferent - What do I take a dependency on?

• Efferent - What takes a dependency on me?

Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
But it’s also a little about data loss
When Servers Crash

[HTTP] $$ Order
Call 1 of 3
DB
App Tx Call 2 of 3

Critical
Windows Patch
Rollback
Where’s the order!?
Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com
When Databases Are Down

[HTTP] $$ Order Call 1 of 3


DB
App Tx
Exception
Write to log Down

Where’s the order!?


Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com
When Deadlocks Happen

[HTTP] $$ Order
Call 1 of 3
DB
App Tx Call 2 of 3
Exception
Write to log A B

Where’s the order!? Deadlock

Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com


Data Loss Using Web Services
Rollback

$$ Order

A B C D

Not Rolled back


[HTTP] Invoke
DB
WS Deadlock

Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com


So What is SOA and what are
messaging systems?
Bus vs. Broker vs. RPC
.NET JAVA
WCF WEB
Service Broker Service

External SVC A SVC B


JSON SalesForce
Service BUS BUS
SAP

Service Service C
A
Service Service D BUS
B
Service E SVC C
Service
C Service F
What makes up a messaging
system
 Messages travel between queues
 Queues are persistent stores located on the machine the
service is deployed to
 Queues can persist messages to non volatile storage in case
of faults
 Adding and removing messages from queues can be
transactional
 Queues provide us with our asynchronous behavior
So How does messaging help with
coupling?
Platform Temporal

Spatial
Afferent

Efferent

• XML for message format & XSD for message schema

• Communication protocol and addressing is a problem

Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent

• Asynchronous messaging

Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent

• Create logically autonomous services

• Address services logically not physically

Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
Platform Temporal

Spatial
Afferent

Efferent

• Use the message schema to create a level of indirection


between services so there is no direct dependency
Schema A Schema B

Service A Service B

Communications Infrastructure
Some diagrams adapted from material by Udi Dahan – The Software Simplist http://www.udidahan.com
And with data loss?
Messages are transactions
Rollback
$$ Order
Q Tx
Receive

Rollback
Call 1 of 3 DB
App Call 2 of 3

The order is back in the queue


Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com
Web Services with Messaging
The message won’t be sent if there’s a failure

$$ Order

A B C D
Msg

[HTTP]
Messaging
Invoke
Gateway DB
WS

Slide courtesy of Udi Dahan – The Software Simplist http://www.udidahan.com


So messaging is the silver bullet ;)

Let’s look at some patterns


Return Address Pattern

 Provides a place to specify a physical address per message,


allowing of logical addressing per message type
 Now EndpointA can do other work while waiting for it’s
response
Load Balancing with Return
Address

 EndpointA can specify an endpoint under less load to process


the response if it has that information
Correlated Request/Response

 An extension of Return Address


 Allows services to maintain state
Multiple Responses with Correlated
Request/Response

 User may not know or care about ALL of the responses


Multiple Handlers with Correlated
Request/Response

 Ultimate in SRP
Publish/Subscribe

 Allows us to add Events to our modeling arsenal


 By subscribing to message types from a logical address we are only coupled to
schema
 This allows us to trivially increase parallelism as required
Modeling Business with Messaging
Systems

 Simpler more Robust systems


Resources and Thanks
 http://www.nservicebus.com/
 service-orientated-architecture@yahoogroups.com
 nservicebus@yahoogroups.com
 dddcqrs+noreply@googlegroups.com
 If you are really keen watch this space
http://www.udidahan.com/training/ a truly life changing course
 And many thanks to Udi for letting me steal his pretty animated
slides and a diagram here and there. Made me look better than I
deserved and saved me heaps of work

You might also like