新手问题 - 我错过了什么?是否有可用的 dotnetcore 2.2 Saga 示例?
我有一个基本的端到端系统工作正常,消息在 docker-compose 中跨容器流动,但添加 Saga 似乎是一个挑战 -
问:我是否缺少调度程序依赖项?在 MassTransit 5.5.5 中,cfg.UseInMemoryMessageScheduler(); 不编译。
发生了一些奇怪的事情,我不得不将我的状态机明确标记为 ISaga
MassTransit.ConfigurationException:无法为 Model.WorkflowExecutionStateMachine 创建状态机连接器 ---> MassTransit.ConfigurationException:未正确配置状态机:workflowapi_1 | [失败] 未指定 ExecutingTask
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// Register MassTransit
services.AddMassTransit(x =>
{
x.AddConsumer<WorkflowTaskConsumer>();
// required?
x.AddSaga<WorkflowExecutionSaga>();
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var rabbitMQHostName = $"rabbitmq://{configuration["RabbitMQHostName"]}";
Console.Out.WriteLineAsync($"Starting Workflow Receiver... {rabbitMQHostName}/{QueueNames.ExeuteWorkflowTaskQueue}");
var host = cfg.Host(new Uri(rabbitMQHostName), hostConfig =>
{
hostConfig.Username("guest");
hostConfig.Password("guest");
});
// A basic message works OK
cfg.ReceiveEndpoint(host, QueueNames.ExeuteWorkflowTaskQueue, ep =>
{
ep.PrefetchCount = 1;
ep.UseMessageRetry(mr => mr.Interval(1000, 2));
ep.ConfigureConsumer<WorkflowTaskConsumer>(provider);
});
// Doesn't like this
cfg.ReceiveEndpoint(host, QueueNames.WorkflowStateMachineSagaQueueName, ep =>
{
ep.PrefetchCount = 1;
ep.UseMessageRetry(mr => mr.Interval(1000, 2));
ep.StateMachineSaga(new WorkflowExecutionSaga(), new InMemorySagaRepository<WorkflowExecutionStateMachine>());
});
}));
cfg.UseInMemoryMessageScheduler(); // doesn't compile!
});
}
巴士启动如下 -
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios,
// see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseMvc();
var bus = app.ApplicationServices.GetService<IBusControl>();
var busHandle = TaskUtil.Await(() =>
{
return bus.StartAsync();
});
lifetime.ApplicationStopping.Register(() =>
{
busHandle.Stop();
});
}
异常详细信息是
未处理的异常:MassTransit.ConfigurationException:无法为 Rapid.Workflow.Api.Model.WorkflowExecutionStateMachine 创建状态机连接器 ---> MassTransit.ConfigurationException:未正确配置状态机:workflowapi_1 | [失败] ExecutingTask 未指定 workflowapi_1 | 在 Automatonymous.StateMachineConfigurationResult.CompileResults(IEnumerable 1 results)
workflowapi_1 | at Automatonymous.StateMachineConnectors.StateMachineConnector
1.StateMachineEvents()+MoveNext() workflowapi_1 | 在 System.Collections.Generic.List 1.AddEnumerable(IEnumerable
1 可枚举) workflowapi_1 | 在 System.Linq.Enumerable.ToList[TSource](IEnumerable 1 source)
workflowapi_1 | at Automatonymous.StateMachineConnectors.StateMachineConnector
1..ctor(SagaStateMachine 1 stateMachine)
workflowapi_1 | --- End of inner exception stack trace ---
workflowapi_1 | at Automatonymous.StateMachineConnectors.StateMachineConnector
1..ctor(SagaStateMachine 1 stateMachine)
workflowapi_1 | at Automatonymous.SagaConfigurators.StateMachineSagaConfigurator
1..ctor(SagaStateMachine1 stateMachine, ISagaRepository
1 个存储库,ISagaConfigurationObserver 观察者)workflowapi_1 | 在 MassTransit.AutomatonymousReceiveEndpointExtensions.StateMachineSaga[TInstance](IReceiveEndpointConfigurator 配置器,SagaStateMachine 1 stateMachine, ISagaRepository
1 存储库,Action`1 配置) workflowapi_1 | 在 Rapid.Workflow.Api.Startup.<>c.b__2_5(IRabbitMqReceiveEndpointConfigurator ep) 在 /src/Workflow.Api/Startup.cs:line 74
依赖项是
<PackageReference Include="Automatonymous" Version="4.1.6" />
<PackageReference Include="MassTransit" Version="5.5.5" />
<PackageReference Include="MassTransit.RabbitMQ" Version="5.5.5" />
<PackageReference Include="MassTransit.AspNetCore" Version="5.5.5" />
<PackageReference Include="MassTransit.Automatonymous" Version="5.5.5" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="5.5.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
感谢您的任何提示或想法 -