1

Nservicebus 处理程序面临的问题。处理程序执行多次。请在下面找到代码。运行此代码后面临问题,letthandler 类中的处理程序被多次执行。

Lett 处理程序类

public Task Handle(Message message, IMessageHandlerContext context)
        {
            Log.Info($"Processing started");
            return Task.CompletedTask;
        }

行为类

public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next)
        {
            //// custom logic before calling the next step in the pipeline.

            await next().ConfigureAwait(false);

            // custom logic after all inner steps in the pipeline completed.

            await context.Publish(context.Message.Instance, this.RetrieveOptions(context)).ConfigureAwait(false);
        }

        private PublishOptions RetrieveOptions(IIncomingLogicalMessageContext context)
        {
            var publishOptions = new PublishOptions();
            publishOptions.RequireImmediateDispatch();

            string requestPoolCounter;
            if (context.MessageHeaders.TryGetValue(Header.SentPoolCounter, out requestPoolCounter))
            {
                publishOptions.SetHeader(Header.SentPoolCounter, requestPoolCounter);
            }

            string primaryKey;
            if (context.MessageHeaders.TryGetValue(Header.PrimaryKey, out primaryKey))
            {
                publishOptions.SetHeader(Header.PrimaryKey, primaryKey);
            }

            string crmEntity;
            if (context.MessageHeaders.TryGetValue(Header.EntityType, out crmEntity))
            {
                publishOptions.SetHeader(Header.EntityType, crmEntity);
            }

            return publishOptions;
        }

处理程序连接器类

public override Task Invoke(IIncomingLogicalMessageContext context, Func<IInvokeHandlerContext, Task> stage)
        {
            context.MessageHandled = true;
            return Task.CompletedTask;
        }

似乎在执行代码之后
等待 context.Publish(context.Message.Instance, this.RetrieveOptions(context)).ConfigureAwait(false); 在 Behavior 类中,lett 处理程序句柄被执行,并且该循环将继续。不确定是什么问题。最近项目参考从 4 更新到 7.2 Nservicebus。有什么建议么?

4

0 回答 0