2
votes

In NServiceBus 3.0.3 I have written a saga. Based on what I'm seeing in the CQRS paradigm, when we see past tense, that should coincide with an event. I want to make sure I don't have business logic in my saga. My assumption in building the saga is that it would receive events and issue commands based on the event that came in as well as certain data elements stored on the saga. The issue I'm running into is that the Saga by default cannot subscribe to published events. I've tried in the EndPointConfig setting up the IWantToRunAtStartup and in the Run method executing

Bus.Subscribe<CustomerBilledEvent>();  

I've tried creating a handler in the same assembly with saga and still no dice.

My app.config for both the saga (hosted by Nservicebus.host.exe) and the publisher (a service in a console application) both have the message endpoints configured as such

 <add Messages="Events.CustomerBilledEvent, Events" Endpoint="orderservice"/>

IHandleMessages has been configured on the Saga as well as the mapping has been configured on the orderid.

IHandleMessages<CustomerBilledEvent>

ConfigureMapping<CustomerBilledEvent>(s => s.OrderId, m=> m.OrderId);

I'm a little lost as to why I can't get the Saga to subscribe to this event. I understand they do not auto subscribe by default but when I look at samples under Udi and John's blogs, I see past tense being sent (IEvent?) to the saga and them issuing Bus.Send which I infer to be commands (ICommand).

1
Is the publisher of CustomerBilledEvent the "orderservice" endpoint?Udi Dahan
No, the publisher of the event is another service. The way I have it set up is that the OrderService (probably should be renamed the OrderSagaService) fires a command that is sent to the BillingService. The billingservice would perform it's logic then publish the CustomerbilledEvent which I was hoping could find it's way back to this orderservice to A)Mark that Saga property "customerbilled" and then B) fire off the next command. This is all sample code I'm working on to better understand how to leverage ICommand and IEvent within Sagas. If off base, any direction is welcome.Robert Larson
Sagas do auto subcribe in 3.0 , have you setup,a subscription storage for the billing service? Also make sure that its using 3.0.3 as well?Andreas Öhlund
Right now I'm using the in-memory provider and all services are on the same machine. Is what you're suggesting is to replicate the saga into each of the services so the publish can be received locally over the same shared storage or is there another strategy I can use that would enable me to have the saga subscribe to these events? I will verify later this evening that 3.0.3 is deployed for the entire project. I was originally leveraging 3.0.1 when I started the implementation and received a notice on Thursday I believe about 3.0.3's release.Robert Larson
No change in upgrading the billing service to 3.0.3. I also looked at the error queue and didn't find anything in there. Is there some documentation or sample that would walk through using Sagas and the IEvent/ICommand messages?Robert Larson

1 Answers

1
votes

So the problem is that you've set it up that your saga is trying to subscribe to the "orderservice" endpoint to be notified about the CustomerBilledEvent, but that endpoint isn't publishing it.