d60developing smart software solutions                                      Ride the bus!                                 ...
Mogens	  Heller	  Grabe	              	              	               	        mhg@d60.dk	        @mookid8000	   h8p://mook...
Agenda	  •  What	  is	  messaging	  •  Doing	  it	  with	  NServiceBus	  •  Enter	  the	  saga	  
What	  is	  messaging?	  void	  CreatePresentation(string	  name);	  	  -­‐-­‐	  	  someObject.CreatePresentation(“Ride	  ...
What	  is	  messaging?	  •  Networks	  are	  unreliable	  •  Inter-­‐process	  communicaKon	  is	  dead	  slow	  •  The	  ...
What	  is	  messaging?	  void	  CreatePresentation(CreatePresentationArgs	  args);	  	  -­‐-­‐	  	  var	  args	  =	  new	 ...
What	  is	  messaging?	  void	  Process(Args	  args);	  	  -­‐-­‐	  	  someObject.Process(new	  CreatePresentation	  {	   ...
What	  is	  messaging?	          void	  
InteresKng	  properKes	     •  Can	  be	  persisted	     •  Can	  be	  forwarded	     •  etc	  
Persisted?	  
MSMQ	  can	  do	  that!	  •  Ships	  with	  all	  modern	  versions	  of	  Windows	  •  Your	  MSMQ	  endpoint	  is	  alwa...
Bus?	  
•  Each	  service	  has	  its	     own	  input	  queue.	  •  When	  a	  service	  needs	     to	  send	  a	  message,	    ...
Messaging	  Pa8erns	  
“Request/reply”	          +	  “Return	  address”	  	  +	  maybe	  “CorrelaKon	  idenKfier”	  
“Publish/subscribe”	  
“Publish/subscribe”	  
Request/reply	  vs.	  Publish/subscribe	  
“Process	  manager”	  +	  “CorrelaKon	  idenKfier”	  
How	  to	  do	  these	  things	  IRL	         •  Commercial	            –  NServiceBus	         •  Free	  alternaKves	    ...
NServiceBus	  •  Currently	  in	  version	  3.0	  •  Licensing	      –  <=	  2.0	  are	  free	      –  >=	  2.5	  cost	  m...
Show	  me	  the	  code	  •  Now	  let’s	  see	  how	  “Request/reply”	  looks	  with	     NServiceBus	      –  We	  have	 ...
Show	  me	  the	  code	  •  Now,	  let’s	  see	  an	  example	  with	  some	  Pub/sub	  acKon	      –  We	  have	  a	  ser...
What	  just	  happened?	  
What	  just	  happened?	  
The	  real	  world	  is	  a	  place...	  •  ...where	  we	  can’t	  always	  process	  messages	  in	     a	  stateless	  ...
Enter	  the	  saga!	  •  A	  model	  for	  long-­‐lived	  transacKons.	  •  “A	  long-­‐lived	  transacKon	  is	  a	  saga...
Sagas	  •  Implemented	  with	  an	  implementaKon	  of	     ISagaEntity,	  TEntity	  and	  deriving	  a	     message	  ha...
Show	  me	  the	  code	  •  Just	  do	  it	  
Sagas	  •  Use	  them	  to	      –  implement	  short	  conversaKons	      –  implement	  long	  conversaKons	      –  han...
Thanks	  for	  listening!	          mhg@d60.dk	          @mookid8000	     h8p://mookid.dk/oncode	  
Image	  credits	  “It’s	  the	  same	  mouth,	  just	  flipped”:	  h8p://humor-­‐image.com/its-­‐the-­‐same-­‐mouth-­‐just-...
Ride The Bus!
Ride The Bus!
Ride The Bus!
Ride The Bus!
Upcoming SlideShare
Loading in...5
×

Ride The Bus!

2,456

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,456
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ride The Bus!

  1. 1. d60developing smart software solutions Ride the bus! April 2012
  2. 2. Mogens  Heller  Grabe         mhg@d60.dk   @mookid8000   h8p://mookid.dk/oncode  
  3. 3. Agenda  •  What  is  messaging  •  Doing  it  with  NServiceBus  •  Enter  the  saga  
  4. 4. What  is  messaging?  void  CreatePresentation(string  name);    -­‐-­‐    someObject.CreatePresentation(“Ride  The  Bus!”);  
  5. 5. What  is  messaging?  •  Networks  are  unreliable  •  Inter-­‐process  communicaKon  is  dead  slow  •  The  other  process  might  not  be  there  at  the   moment  •  etc  •  etc  
  6. 6. What  is  messaging?  void  CreatePresentation(CreatePresentationArgs  args);    -­‐-­‐    var  args  =  new  CreatePresentationArgs  {    Title  =  “Ride  The  Bus!”  };    someObject.CreatePresentation(args);  
  7. 7. What  is  messaging?  void  Process(Args  args);    -­‐-­‐    someObject.Process(new  CreatePresentation  {    Title  =  “Ride  The  Bus!”  });    someObject.Process(new  Something());    someObject.Process(new  SomethingElse());  
  8. 8. What  is  messaging?   void  
  9. 9. InteresKng  properKes   •  Can  be  persisted   •  Can  be  forwarded   •  etc  
  10. 10. Persisted?  
  11. 11. 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).  
  12. 12. Bus?  
  13. 13. •  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.  
  14. 14. Messaging  Pa8erns  
  15. 15. “Request/reply”   +  “Return  address”    +  maybe  “CorrelaKon  idenKfier”  
  16. 16. “Publish/subscribe”  
  17. 17. “Publish/subscribe”  
  18. 18. Request/reply  vs.  Publish/subscribe  
  19. 19. “Process  manager”  +  “CorrelaKon  idenKfier”  
  20. 20. How  to  do  these  things  IRL   •  Commercial   –  NServiceBus   •  Free  alternaKves   –  MassTransit   –  RhinoESB   –  Rebus(*)  
  21. 21. NServiceBus  •  Currently  in  version  3.0  •  Licensing   –  <=  2.0  are  free   –  >=  2.5  cost  money  
  22. 22. 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.  
  23. 23. 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.  
  24. 24. What  just  happened?  
  25. 25. What  just  happened?  
  26. 26. 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...  
  27. 27. 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    
  28. 28. 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.  
  29. 29. Show  me  the  code  •  Just  do  it  
  30. 30. Sagas  •  Use  them  to   –  implement  short  conversaKons   –  implement  long  conversaKons   –  handle  Kmeouts   –  implement  idempotency  
  31. 31. Thanks  for  listening!   mhg@d60.dk   @mookid8000   h8p://mookid.dk/oncode  
  32. 32. 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.  
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×