Messaging Patterns

Preview:

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Messaging PatternsAn alternative approach to modeling with ESB’s

Jimmy P@pjimmymail@thejimmyp.comhttp://www.blog.thejimmyp.com

OutlineSome Context

Some Problems Intro to Messaging SystemsSome Solutions

And The FocusSome Patterns

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

It’s mainly about coupling

Efferent

Afferent

Platform Temporal

Spatial

Efferent

Afferent

Platform Temporal

Spatial

• AKA interoperability

• Most RPC and other common messaging technologies are platform

• dependent in painful places

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

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

A BA Calls B

B Returns

A Blocks WhileB Processes

B Processes

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• 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 Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• Afferent - What do I take a dependency on?

• Efferent - What takes a dependency on me?

But it’s also a little about data loss

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

When Servers Crash

DBApp[HTTP] $$ Order

TxCall 1 of 3

Call 2 of 3

Critical Windows Patch

RollbackWhere’s the order!?

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

App[HTTP] $$ Order

Tx

When Databases Are Down

Exception

Write to log

DBCall 1 of 3

Down

Where’s the order!?

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

TxApp[HTTP] $$ Order

When Deadlocks Happen

DBCall 1 of 3

Deadlock

ExceptionWrite to log A B

Call 2 of 3

Where’s the order!?

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

Data Loss Using Web Services

A B C D

WSDB

[HTTP] Invoke

$$ Order

Deadlock

Rollback

Not Rolled back

So What is SOA and what are messaging systems?

Bus vs. Broker vs. RPC

Service C

Service B

Service A

Broker

.NETWCF

Service

JAVA WEB

Service

SAP

SVC A

BUS

SVC B

BUS

SVC C

BUS

External JSON

ServiceSalesForc

e

Service F

Service C

Service D

Service E

What makes up a messaging system

Messages travel between queuesQueues are persistent stores located on the

machine the service is deployed toQueues can persist messages to non volatile

storage in case of faultsAdding and removing messages from queues

can be transactionalQueues provide us with our asynchronous

behavior

So How does messaging help with coupling?

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• 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 Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• Asynchronous messaging

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• Create logically autonomous services

• Address services logically not physically

Some diagrams adapted from material by Udi Dahan – The Software Simplisthttp://www.udidahan.com

Efferent

Afferent

Platform Temporal

Spatial

• Use the message schema to create a level of indirection between services so there is no direct dependency

Service A

Communications Infrastructure

Schema A

Service B

Schema B

And with data loss?

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

Tx

Messages are transactions

Q$$ Order

App

Receive

DBCall 1 of 3

Rollback

Call 2 of 3

Rollback

The order is back in the queue

Slide courtesy of Udi Dahan – The Software Simplist

http://www.udidahan.com

Web Services with Messaging

MessagingGateway

A B C D

WS

Msg

DB

$$ Order

[HTTP] Invoke

The message won’t be sent if there’s a failure

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 AddressAllows services to maintain state

Multiple Responses with Correlated

Request/Response

User may not know or care about ALL of the responses

Ultimate in SRP

Multiple Handlers with Correlated

Request/Response

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

Simpler more Robust systems

Modeling Business with Messaging Systems

Resources and Thankshttp://www.nservicebus.com/service-orientated-architecture@yahoogroups.comnservicebus@yahoogroups.comdddcqrs+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

Recommended