Ride The Bus!
-
Upload
mogens-heller-grabe -
Category
Technology
-
view
2.448 -
download
1
Transcript of Ride The Bus!
![Page 1: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/1.jpg)
d60 developing smart software solutions
Ride the bus! April 2012
![Page 3: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/3.jpg)
Agenda
• What is messaging • Doing it with NServiceBus • Enter the saga
![Page 4: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/4.jpg)
What is messaging?
void CreatePresentation(string name); -‐-‐ someObject.CreatePresentation(“Ride The Bus!”);
![Page 5: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/5.jpg)
What is messaging?
• Networks are unreliable • Inter-‐process communicaKon is dead slow • The other process might not be there at the moment
• etc • etc
![Page 6: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/6.jpg)
What is messaging?
void CreatePresentation(CreatePresentationArgs args); -‐-‐ var args = new CreatePresentationArgs {
Title = “Ride The Bus!” }; someObject.CreatePresentation(args);
![Page 7: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/7.jpg)
What is messaging?
void Process(Args args); -‐-‐ someObject.Process(new CreatePresentation {
Title = “Ride The Bus!” }); someObject.Process(new Something()); someObject.Process(new SomethingElse());
![Page 8: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/8.jpg)
What is messaging?
void
![Page 9: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/9.jpg)
InteresKng properKes
• Can be persisted • Can be forwarded • etc
![Page 10: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/10.jpg)
Persisted?
![Page 11: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/11.jpg)
MSMQ can do that!
• Ships with all modern versions of Windows • Your MSMQ endpoint is always local – remoKng is taken care of via outgoing queues
• .NET client in System.Messaging (GAC).
![Page 12: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/12.jpg)
Bus?
![Page 13: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/13.jpg)
![Page 14: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/14.jpg)
![Page 15: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/15.jpg)
• Each service has its own input queue.
• When a service needs to send a message, the bus looks up the desKnaKon somehow.
• How desKnaKons are looked up depends on whether the service is sending or publishing.
![Page 16: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/16.jpg)
![Page 17: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/17.jpg)
Messaging Pa8erns
![Page 18: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/18.jpg)
“Request/reply”
+ “Return address” + maybe “CorrelaKon idenKfier”
![Page 19: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/19.jpg)
“Publish/subscribe”
![Page 20: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/20.jpg)
“Publish/subscribe”
![Page 21: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/21.jpg)
Request/reply vs. Publish/subscribe
![Page 22: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/22.jpg)
![Page 23: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/23.jpg)
“Process manager”
+ “CorrelaKon idenKfier”
![Page 24: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/24.jpg)
How to do these things IRL
• Commercial – NServiceBus
• Free alternaKves – MassTransit – RhinoESB – Rebus(*)
![Page 25: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/25.jpg)
NServiceBus
• Currently in version 3.0
• Licensing – <= 2.0 are free – >= 2.5 cost money
![Page 26: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/26.jpg)
Show me the code
• Now let’s see how “Request/reply” looks with NServiceBus – We have a pre8y unreliable web service, umm “Whatchamacallit”, that we want to call.
– We build an integraKon service with NServiceBus that works as a messaging façade towards the web service.
– Our system requests stuff from the façade, the façade replies.
![Page 27: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/27.jpg)
Show me the code
• Now, let’s see an example with some Pub/sub acKon – We have a service that processes something, “Somekindofprocessor”, when it receives a ProcessSomething command.
– In order to process stuff, it needs to get the important string from our unreliable web service from before.
– When processing is done, it should publish the result, allowing any other interested services to react to this.
![Page 28: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/28.jpg)
What just happened?
![Page 29: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/29.jpg)
What just happened?
![Page 30: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/30.jpg)
The real world is a place...
• ...where we can’t always process messages in a stateless manner like this...
• ...where mulKple things need coordinaKon and will not always succeed/fail as a whole...
![Page 31: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/31.jpg)
Enter the saga!
• A model for long-‐lived transacKons. • “A long-‐lived transacKon is a saga if it can be wri8en as a sequence of transacKons that can be interleaved with other transacKons.”
• For some reason, Mike Amundsen keeps a copy of the original whitepaper PDF here: h8p://www.amundsen.com/downloads/sagas.pdf
![Page 32: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/32.jpg)
Sagas
• Implemented with an implementaKon of ISagaEntity, TEntity and deriving a message handler from Saga<TEntity>.
• All handled messages should somehow be correlated with the sata data.
![Page 33: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/33.jpg)
Show me the code
• Just do it
![Page 34: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/34.jpg)
Sagas
• Use them to – implement short conversaKons – implement long conversaKons – handle Kmeouts – implement idempotency
![Page 36: Ride The Bus!](https://reader034.fdocuments.in/reader034/viewer/2022042607/555cba7bd8b42a5f718b478b/html5/thumbnails/36.jpg)
Image credits “It’s the same mouth, just flipped”: h8p://humor-‐image.com/its-‐the-‐same-‐mouth-‐just-‐flipped/ Thanks for lepng me borrow your awesome images – if you ever meet me, I’ll buy you guys and girls a beer. Seriously, I will.