c# - 处理程序多次执行问题
问题描述
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。有什么建议么?
解决方案
推荐阅读
- javascript - 带有类实例的 JavaScript 扩展运算符
- android - 在 Kotlin 中的两个活动之间传输位图
- google-cloud-firestore - firestore 可以以什么速率在集合中创建新文档?
- flutter - Flutter:如何根据图像的 XY 百分比位置插入图标/动作
- r - 如何识别包含多个宽峰的数据中的主峰
- c++ - c ++中的模板实际上如何在后台工作?
- javascript - 如何在不检查任何单选按钮的情况下以 HTML 格式提交表单?
- csv - AMCharts - 使用不同的数据源导出 CSV,而不是用于创建图表的数据
- sparql - 为什么此 Wikidata SPARQL 查询仅适用于列表中的第一个元素?
- python-3.x - 连接具有不同分辨率(通常为 1080 或 720)的视频的最佳方法