Hi,
I'm having a go at setting up a saga based on the Starbucks sample (i.e. using the magnum state machine); for the time being I've reduced it to a single state change (from initial to complete), but for some reason, all messages after the first one trigger a SagaException stating that "The message cannot be accepted by an existing saga" (Thrown by InitiatingSagaPolicy.CanUseExistingInstance).
Here's the code...
The startup bit:
WindsorContainer container = new WindsorContainer();
container.Register(
Component.For(typeof(ISagaRepository<>))
.ImplementedBy(typeof(InMemorySagaRepository<>))
.LifeStyle.Singleton,
Component.For<ScriptGeneratorSaga>(),
Component.For<IServiceBus>().UsingFactoryMethod(() =>
{
return ServiceBusFactory.New(sbc =>
{
sbc.ReceiveFrom(busConfiguration.QueueAddress);
sbc.UseRabbitMq();
sbc.Subscribe(subs => { subs.LoadFrom(container); });
});
}).LifeStyle.Singleton);
using(IServiceBus bus = container.Resolve<IServiceBus>())
{
bus.WriteIntrospectionToConsole();
Console.WriteLine("Press return to exit....");
Console.ReadLine();
}
The saga configuration:
public class ScriptGeneratorSaga :
SagaStateMachine<ScriptGeneratorSaga>,
ISaga
{
public IServiceBus Bus { get; set; }
public Guid CorrelationId { get; set; }
//mandatory start and end
public static State Initial { get; set; }
public static State Completed { get; set; }
public static State Pending { get; set; }
public static State InProgress { get; set; }
public static State Success { get; set; }
public static State Failure { get; set; }
public static State Exception { get; set; }
public static Event<GenerateScriptBySiteRequestMessage> GenerateScriptBySiteRequest { get; set; }
public static Event<GenerateScriptByNetworkControllerRequestMessage> GenerateScriptByNetworkControllerRequest { get; set; }
static ScriptGeneratorSaga()
{
Define(() =>
{
Initially(
When(GenerateScriptBySiteRequest)
.Then((saga, message) =>
{
Console.WriteLine("Got GenerateScriptBySiteRequest.");
})
.Complete());
});
}
public ScriptGeneratorSaga(Guid correlationId)
{
CorrelationId = correlationId;
}
}
The starbucks sample works fine, and I've no idea what I'm doing wrong (I've even replicated the startup process from the barista project, just in case there was something weird being done under the covers...).
I'm stumped...thoughts, anyone?
Thanks.