0

有没有办法以通用方式处理 NotAcceptedStateMachineException,例如以请求-响应方法向客户端返回一些用户友好的消息?

    Automatonymous.NotAcceptedStateMachineException: ExampleSagaState(8dc388ea-99b3-4d21-a3e5-915c4185ec12) Saga exception on receipt of IExampleRequest: Not accepted in state ExampleState
 ---> Automatonymous.UnhandledEventException: The ExampleEvent event is not handled during the ExampleState state for the ExampleStateMachineSaga state machine
   at Automatonymous.AutomatonymousStateMachine`1.DefaultUnhandledEventCallback(UnhandledEventContext`1 context)
   at Automatonymous.AutomatonymousStateMachine`1.UnhandledEvent(EventContext`1 context, State state)
   at Automatonymous.States.StateMachineState`1.Automatonymous.State<TInstance>.Raise[T](EventContext`2 context)
   at Automatonymous.AutomatonymousStateMachine`1.Automatonymous.StateMachine<TInstance>.RaiseEvent[T](EventContext`2 context)
   at Automatonymous.Pipeline.StateMachineSagaMessageFilter`2.Send(SagaConsumeContext`2 context, IPipe`1 next)
   --- End of inner exception stack trace ---
   at Automatonymous.Pipeline.StateMachineSagaMessageFilter`2.Send(SagaConsumeContext`2 context, IPipe`1 next)
   at Automatonymous.Pipeline.StateMachineSagaMessageFilter`2.Send(SagaConsumeContext`2 context, IPipe`1 next)
   at MassTransit.Saga.SendSagaPipe`2.Send(SagaRepositoryContext`2 context)
   at MassTransit.Saga.SendSagaPipe`2.Send(SagaRepositoryContext`2 context)
   at MassTransit.RedisIntegration.Contexts.RedisSagaRepositoryContextFactory`1.Send[T](ConsumeContext`1 context, IPipe`1 next)
   at .MassTransit.RedisIntegration.Contexts.RedisSagaRepositoryContextFactory`1.Send[T](ConsumeContext`1 context, IPipe`1 next)
   at MassTransit.Saga.Pipeline.Filters.CorrelatedSagaFilter`2.GreenPipes.IFilter<MassTransit.ConsumeContext<TMessage>>.Send(ConsumeContext`1 context, IPipe`1 next)

我正在使用请求/响应来执行状态机:

  IRequestClient<IExampleRequest> client = this._busControl.CreateRequestClient<IExampleMessage>(address, (MassTransit.RequestTimeout)Timeout);
  Response<IExampleResponse> response = await client.GetResponse<TRes>(message, new CancellationToken(), new MassTransit.RequestTimeout()).ConfigureAwait(false);

我想得到该 TRes 类型的响应,但显示的是超时。我试图通过使用 OnUnhandledEvent 来处理这个问题,但在这里我丢失了有关响应类型的信息,所以我无法将其发回。任何想法如何解决这个问题?谢谢

4

1 回答 1

0

没有看到状态机代码,纯属猜测,但错误信息很清楚。状态机不处于处理该事件的状态。

我建议查看一些涵盖状态机的示例,如果可能的话,观看整个赛季的视频讨论该示例、状态机以及它们如何在 MassTransit 中工作。

于 2021-12-01T13:23:17.357 回答