SlideShare a Scribd company logo
1 of 38
Download to read offline
Dennis van der Stelt
all your batch jobs are belong to us
Dennis van der Stelt
Software Architect
http://dennis.bloggingabout.net/
dennis@bloggingabout.net
Particular Software engineer
death of the batch job
@dvdstelt
#nservicebus
Dennis van der Stelt
AGENDA
Dennis van der Stelt
NServiceBus
In Particular
Dennis van der Stelt
NServiceBus
It’s not like WCF, which does RPC
But closer to WCF than to BizTalk
Dennis van der Stelt
BUS TOPOLOGY
Dennis van der Stelt
Messaging
What is it and why do I need it?
Dennis van der Stelt
SpatialTemporalPlatform
coupling aspects
demo
Quick NServiceBus Demo
Dennis van der Stelt
NServiceBus Sagas
A pattern by relation database community
Dennis van der Stelt
Dennis van der Stelt
PROCESS MANAGER
process managerInitiating message
demo
NServiceBus Sagas
Dennis van der Stelt
Sagas Recap
“What have you done” – Within Temptation
Dennis van der Stelt
HANDLING MESSAGES
Behavior like normal message handlers
class MySaga : IHandleMessages<MyMessage>
{
public void Handle(MyMessage message)
{
…
}
}
Dennis van der Stelt
STARTING SAGAS
Extends the default IHandleMessages<T>
class MySaga : IAmStartedByMessages<MyMessage>
{
public void Handle(MyMessage message)
{
…
}
}
Dennis van der Stelt
STORING STATE
Extends the default IHandleMessages<T>
class MySaga : Saga<MySagaData>,
IAmStartedByMessages<MyMessage>
{
public void Handle(MyMessage message)
{
this.Saga.Data.MyStateProperty = Message.MyProperty;
}
}
Dennis van der Stelt
CORRELATING MESSAGES TO SAGA INSTANCE
class MySaga : Saga<MySagaData>,
IAmStartedByMessages<MyMessage>
{
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<MySagaData> mapper)
{
mapper.ConfigureMapping<MyMessage>(m => m.MyProperty).ToSaga(s => s.MyStateProperty);
}
public void Handle(MyMessage message)
{
this.Saga.Data.MyStateProperty = Message.MyProperty;
}
}
Dennis van der Stelt
REQUESTING TIMEOUTS
Reminders to the Saga itself
class MySaga : Saga<MySagaData>,
IAmStartedByMessages<MyMessage>,
IHandleTimeouts<MyTimeout>
{
public void Handle(MyMessage message)
{
this.Saga.Data.MyStateProperty = Message.MyProperty;
RequestTimeout<MyTimeout>(TimeSpan.FromSeconds(10));
}
public void Timeout(MyTimeout state)
{
…
}
}
Dennis van der Stelt
SENDING MESSAGES
Reminders to the Saga itself
class MySaga : Saga<MySagaData>,
IAmStartedByMessages<MyMessage>
{
public void Handle(MyMessage message)
{
this.Saga.Data.MyStateProperty = Message.MyProperty;
this.Bus.Send(new MyCommand());
this.Bus.Publish(new MyEvent());
}
}
Dennis van der Stelt
SAGA STATE
Memento
class MySagaData : IContainSagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
[Unique]
public virtual Guid MySagaId { get; set; }
}
ALTER TABLE [dbo].[MySagaData]
ADD UNIQUE NONCLUSTERED
([MySagaId] ASC) ON [PRIMARY]
Dennis van der Stelt
SAGA STATE
Memento
class MySagaData : IContainSagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
[Unique]
public virtual Guid MySagaId { get; set; }
public virtual IList<Product> Products { get; set; }
}
public class Product
{
public virtual Guid ProductId { get; set; }
}
Dennis van der Stelt
SAGA STATE
Memento
class MySagaData : IContainSagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
[Unique]
public virtual Guid MySagaId { get; set; }
public virtual IList<Product> Products { get; set; }
}
public class Product
{
public virtual Guid ProductId MyUniqueId { get; set; }
}
Dennis van der Stelt
Death to the batch job
Because we don’t want to depend on operations ;-)
Dennis van der Stelt
Dennis van der Stelt
scheduled tasks
Your CEO had insomnia and was using the system in the
middle of the night. The batch job failed somewhere in
the middle of updating 74 million records…
You need to figure out which row it failed on (how?),
why it failed, correct the issue, then start the job again
from where it left off, because if you have to start from
the beginning, it won't get done before peak hours in
the morning.
because that sounds better than batch job
Dennis van der Stelt
BATCH JOB
All customers that ordered $5000 in the last year, get preferred status
DateTime cutoff = DateTime.Today.AddDays(-365);
foreach(var customer in customers)
{
var orderTotal = customer.Orders
.Where(o => o.OrderDate > cutoff)
.Sum(order => order.OrderValue);
customer.Prefered = orderTotal > 5000;
}
Dennis van der Stelt
Tromsø, Norway
Dennis van der Stelt
what if
we can see things before they happen?
Dennis van der Stelt
customer preferred status
Dev: Let's say Steve orders something
for $100. At what point does that
amount no longer count toward Steve's
preferred status?
BA: That's easy, after 365 days!
Dennis van der Stelt
-$300-$100
+$300
DURABLE TIMEOUTS
Our way to predict the future
2015 2016
+$100
Dennis van der Stelt
DURABLE TIMEOUTS
public void Handle(OrderPlaced message)
{
this.Data.CustomerId = message.CustomerId;
this.Data.RunningTotal += message.Amount;
this.RequestTimeout<OrderExpired>(TimeSpan.FromDays(365),
timeout => timeout.Amount = message.Amount);
CheckForPreferredStatusChange();
}
public void Handle(OrderExpired message)
{
this.Data.RunningTotal -= message.Amount;
CheckForPreferredStatusChange();
}
Dennis van der Stelt
DURABLE TIMEOUTS
private void CheckForPreferredStatusChange()
{
if(this.Data.PreferredStatus == false && this.Data.RunningTotal >= 5000)
{
this.Bus.Publish<CustomerHasBecomePreferred>(
evt => evt.CustomerId = this.Data.CustomerId);
}
else if(this.Data.PreferredStatus == true && this.Data.RunningTotal < 5000)
{
this.Bus.Publish<CustomerHasBecomeNonPreferred(
evt => evt.CustomerId = this.Data.CustomerId);
}
}
Dennis van der Stelt
Best Practices
The silver bullets?
Dennis van der Stelt
Rule #1 : Don’t query data
Never ever, ever, ever query data
- From the saga to another data source
- Owned by saga with a 3rd party tool
race conditions do not exist
Dennis van der Stelt
STARTING SAGAS
What business events can start a Saga?
class MySaga : Saga<MySagaData>,
IAmStartedByMessages<MyMessage>,
IAmStartedByMessages<YourMessage>,
IAmStartedByMessages<AnotherMesssage>
{
public void Handle(MyMessage message)
{
…
if (VerifyState())
MarkAsComplete();
}
}
sagas bring agility
Dennis van der Stelt
Please…
stay in touch!
http://dennis.bloggingabout.net
dennis@bloggingabout.net

More Related Content

Similar to Death of the batch job

Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom PackageKickstarting SItes With a Custom Package
Kickstarting SItes With a Custom Package
Jeff Segars
 

Similar to Death of the batch job (20)

Distributed Systems principles
Distributed Systems principlesDistributed Systems principles
Distributed Systems principles
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
Beyond php it's not (just) about the code
Beyond php   it's not (just) about the codeBeyond php   it's not (just) about the code
Beyond php it's not (just) about the code
 
Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom PackageKickstarting SItes With a Custom Package
Kickstarting SItes With a Custom Package
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
 
MAKE SENSE OF YOUR BIG DATA
MAKE SENSE OF YOUR BIG DATA MAKE SENSE OF YOUR BIG DATA
MAKE SENSE OF YOUR BIG DATA
 
Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days
 
vDesk.works vs Microsoft Cloud 365 (VDI)
vDesk.works vs Microsoft Cloud 365 (VDI)vDesk.works vs Microsoft Cloud 365 (VDI)
vDesk.works vs Microsoft Cloud 365 (VDI)
 
Redis for your boss 2.0
Redis for your boss 2.0Redis for your boss 2.0
Redis for your boss 2.0
 
Static site gen talk
Static site gen talkStatic site gen talk
Static site gen talk
 
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Getting out of the monolith hell
Getting out of the monolith hellGetting out of the monolith hell
Getting out of the monolith hell
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project Files
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Jakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyJakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testy
 
Into React-DOM.pptx
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptx
 
Ajax-Tutorial
Ajax-TutorialAjax-Tutorial
Ajax-Tutorial
 
The Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol RevealedThe Elastix Call Center Protocol Revealed
The Elastix Call Center Protocol Revealed
 

More from Dennis van der Stelt

More from Dennis van der Stelt (11)

Change your architecture during deployment
Change your architecture during deploymentChange your architecture during deployment
Change your architecture during deployment
 
Dealing with eventual consistency
Dealing with eventual consistencyDealing with eventual consistency
Dealing with eventual consistency
 
Dealing with eventual consistency
Dealing with eventual consistencyDealing with eventual consistency
Dealing with eventual consistency
 
Een andere kijk op Microservices
Een andere kijk op MicroservicesEen andere kijk op Microservices
Een andere kijk op Microservices
 
Duplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro ServicesDuplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro Services
 
Silverlight & WCF RIA
Silverlight & WCF RIASilverlight & WCF RIA
Silverlight & WCF RIA
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Death of the batch job

  • 1. Dennis van der Stelt all your batch jobs are belong to us Dennis van der Stelt Software Architect http://dennis.bloggingabout.net/ dennis@bloggingabout.net Particular Software engineer death of the batch job @dvdstelt #nservicebus
  • 2. Dennis van der Stelt AGENDA
  • 3. Dennis van der Stelt NServiceBus In Particular
  • 4. Dennis van der Stelt NServiceBus It’s not like WCF, which does RPC But closer to WCF than to BizTalk
  • 5. Dennis van der Stelt BUS TOPOLOGY
  • 6. Dennis van der Stelt Messaging What is it and why do I need it?
  • 7. Dennis van der Stelt SpatialTemporalPlatform coupling aspects
  • 9. Dennis van der Stelt NServiceBus Sagas A pattern by relation database community
  • 10. Dennis van der Stelt
  • 11. Dennis van der Stelt PROCESS MANAGER process managerInitiating message
  • 13. Dennis van der Stelt Sagas Recap “What have you done” – Within Temptation
  • 14. Dennis van der Stelt HANDLING MESSAGES Behavior like normal message handlers class MySaga : IHandleMessages<MyMessage> { public void Handle(MyMessage message) { … } }
  • 15. Dennis van der Stelt STARTING SAGAS Extends the default IHandleMessages<T> class MySaga : IAmStartedByMessages<MyMessage> { public void Handle(MyMessage message) { … } }
  • 16. Dennis van der Stelt STORING STATE Extends the default IHandleMessages<T> class MySaga : Saga<MySagaData>, IAmStartedByMessages<MyMessage> { public void Handle(MyMessage message) { this.Saga.Data.MyStateProperty = Message.MyProperty; } }
  • 17. Dennis van der Stelt CORRELATING MESSAGES TO SAGA INSTANCE class MySaga : Saga<MySagaData>, IAmStartedByMessages<MyMessage> { protected override void ConfigureHowToFindSaga(SagaPropertyMapper<MySagaData> mapper) { mapper.ConfigureMapping<MyMessage>(m => m.MyProperty).ToSaga(s => s.MyStateProperty); } public void Handle(MyMessage message) { this.Saga.Data.MyStateProperty = Message.MyProperty; } }
  • 18. Dennis van der Stelt REQUESTING TIMEOUTS Reminders to the Saga itself class MySaga : Saga<MySagaData>, IAmStartedByMessages<MyMessage>, IHandleTimeouts<MyTimeout> { public void Handle(MyMessage message) { this.Saga.Data.MyStateProperty = Message.MyProperty; RequestTimeout<MyTimeout>(TimeSpan.FromSeconds(10)); } public void Timeout(MyTimeout state) { … } }
  • 19. Dennis van der Stelt SENDING MESSAGES Reminders to the Saga itself class MySaga : Saga<MySagaData>, IAmStartedByMessages<MyMessage> { public void Handle(MyMessage message) { this.Saga.Data.MyStateProperty = Message.MyProperty; this.Bus.Send(new MyCommand()); this.Bus.Publish(new MyEvent()); } }
  • 20. Dennis van der Stelt SAGA STATE Memento class MySagaData : IContainSagaData { public virtual Guid Id { get; set; } public virtual string Originator { get; set; } public virtual string OriginalMessageId { get; set; } [Unique] public virtual Guid MySagaId { get; set; } } ALTER TABLE [dbo].[MySagaData] ADD UNIQUE NONCLUSTERED ([MySagaId] ASC) ON [PRIMARY]
  • 21. Dennis van der Stelt SAGA STATE Memento class MySagaData : IContainSagaData { public virtual Guid Id { get; set; } public virtual string Originator { get; set; } public virtual string OriginalMessageId { get; set; } [Unique] public virtual Guid MySagaId { get; set; } public virtual IList<Product> Products { get; set; } } public class Product { public virtual Guid ProductId { get; set; } }
  • 22. Dennis van der Stelt SAGA STATE Memento class MySagaData : IContainSagaData { public virtual Guid Id { get; set; } public virtual string Originator { get; set; } public virtual string OriginalMessageId { get; set; } [Unique] public virtual Guid MySagaId { get; set; } public virtual IList<Product> Products { get; set; } } public class Product { public virtual Guid ProductId MyUniqueId { get; set; } }
  • 23. Dennis van der Stelt Death to the batch job Because we don’t want to depend on operations ;-)
  • 24. Dennis van der Stelt
  • 25. Dennis van der Stelt scheduled tasks Your CEO had insomnia and was using the system in the middle of the night. The batch job failed somewhere in the middle of updating 74 million records… You need to figure out which row it failed on (how?), why it failed, correct the issue, then start the job again from where it left off, because if you have to start from the beginning, it won't get done before peak hours in the morning. because that sounds better than batch job
  • 26. Dennis van der Stelt BATCH JOB All customers that ordered $5000 in the last year, get preferred status DateTime cutoff = DateTime.Today.AddDays(-365); foreach(var customer in customers) { var orderTotal = customer.Orders .Where(o => o.OrderDate > cutoff) .Sum(order => order.OrderValue); customer.Prefered = orderTotal > 5000; }
  • 27. Dennis van der Stelt Tromsø, Norway
  • 28. Dennis van der Stelt what if we can see things before they happen?
  • 29. Dennis van der Stelt customer preferred status Dev: Let's say Steve orders something for $100. At what point does that amount no longer count toward Steve's preferred status? BA: That's easy, after 365 days!
  • 30. Dennis van der Stelt -$300-$100 +$300 DURABLE TIMEOUTS Our way to predict the future 2015 2016 +$100
  • 31. Dennis van der Stelt DURABLE TIMEOUTS public void Handle(OrderPlaced message) { this.Data.CustomerId = message.CustomerId; this.Data.RunningTotal += message.Amount; this.RequestTimeout<OrderExpired>(TimeSpan.FromDays(365), timeout => timeout.Amount = message.Amount); CheckForPreferredStatusChange(); } public void Handle(OrderExpired message) { this.Data.RunningTotal -= message.Amount; CheckForPreferredStatusChange(); }
  • 32. Dennis van der Stelt DURABLE TIMEOUTS private void CheckForPreferredStatusChange() { if(this.Data.PreferredStatus == false && this.Data.RunningTotal >= 5000) { this.Bus.Publish<CustomerHasBecomePreferred>( evt => evt.CustomerId = this.Data.CustomerId); } else if(this.Data.PreferredStatus == true && this.Data.RunningTotal < 5000) { this.Bus.Publish<CustomerHasBecomeNonPreferred( evt => evt.CustomerId = this.Data.CustomerId); } }
  • 33. Dennis van der Stelt Best Practices The silver bullets?
  • 34. Dennis van der Stelt Rule #1 : Don’t query data Never ever, ever, ever query data - From the saga to another data source - Owned by saga with a 3rd party tool
  • 35. race conditions do not exist
  • 36. Dennis van der Stelt STARTING SAGAS What business events can start a Saga? class MySaga : Saga<MySagaData>, IAmStartedByMessages<MyMessage>, IAmStartedByMessages<YourMessage>, IAmStartedByMessages<AnotherMesssage> { public void Handle(MyMessage message) { … if (VerifyState()) MarkAsComplete(); } }
  • 38. Dennis van der Stelt Please… stay in touch! http://dennis.bloggingabout.net dennis@bloggingabout.net