c# - MassTransit - 无法覆盖 RoutingSlipResponseProxy 中的 Consume 方法
问题描述
我正在尝试设置一个RoutingSlipResponseProxy
,如果没有RequestId
. 我试图通过覆盖Consume
my 中的方法来做到这一点RoutingSlipResponseProxy
,如下所示:
public class MigrateResponseProxy : RoutingSlipResponseProxy<IMigrationRequested, IMigrationComplete>
{
public new async Task Consume(ConsumeContext<RoutingSlipCompleted> context)
{
var isRequest = context.Message.Variables.ContainsKey("RequestId");
if (!isRequest)
return;
var request = context.Message.GetVariable<IMigrationRequested>("Request");
var requestId = context.Message.GetVariable<Guid>("RequestId");
Uri responseAddress = null;
if (context.Message.Variables.ContainsKey("ResponseAddress"))
responseAddress = context.Message.GetVariable<Uri>("ResponseAddress");
if (responseAddress == null)
throw new ArgumentException($"The response address could not be found for the faulted routing slip: {context.Message.TrackingNumber}");
var endpoint = await context.GetResponseEndpoint<IMigrationComplete>(responseAddress, requestId).ConfigureAwait(false);
var response = await CreateResponseMessage(context, request);
await endpoint.Send(response).ConfigureAwait(false);
}
... remaining code ...
}
这与原始方法的代码基本相同,只是在开头检查了 RequestId。但是,在通过代码进行调试时,似乎永远不会调用这个被覆盖的方法,而是调用父方法。有什么我可能在这里遗漏的吗?任何帮助,将不胜感激。
解决方案
这些方法不是虚拟的,因此您将无法覆盖它们。在这种情况下,您最好将代理代码复制到您自己的项目中,而不是使用 MassTransit 中包含的实现。
欢迎您提交 PR 以使这些方法虚拟化。
推荐阅读
- css - 使用绝对定位的 Font Awesome 图标修复了 div
- powershell - 获取 COM+ 应用程序列表
- excel - 使用循环将数据从另一个表更新到另一个使用excel vba的表
- go - “导出的类型应该有注释或未导出”golang VS Code
- mysql - SQL for ids 来自同一个表,关系在另一个表中定义
- node.js - 如何在量角器中重新连接查询到数据库
- three.js - 如何逐帧手动控制动画?
- android - dialogflow 应用程序无法在锁定的手机上启动?
- c# - 为什么 ListView 不显示 WPF 上的项目?
- javascript - iFrame 导致父级在加载时滚动到 iFrame 位置