公共交通发送 ICommand

Masstransit sending ICommand

我有一个 ICommand 列表,存储在数据库中用于遗留流程管理器(我还没有时间将所有代码转换为使用 Sagas)

我需要能够反序列化命令列表并发送它们。

为了能够在 c# 中表示命令,我有一个列表

遍历列表并在每个列表上调用发送会导致问题,因为 Masstransit 只看到 ICommand 而不是基础类型(即使命令是使用类型 info

序列化的)

代码示例如下:

if (deserializedCommands == null)
{
   deserializedCommands = this._serializer.Deserialize<IEnumerable<Envelope<ICommand>>>(undispatched.Commands).ToList();

   while (deserializedCommands.Count > 0)
   {
       var cmd = deserializedCommands.First();

       this._commandBus.Publish(cmd.Body).Wait();

       deserializedCommands.RemoveAt(0);
   }
}

在调试器中将鼠标悬停在 cmd.Body 上会显示正确的类型。

但是 Masstransit 只看到 ICommand:

A convention for the message type xxxx.ICommand was not found

我怎样才能让 MT 看到正确的类型?

Google 搜索了一些关于 EndpointConvention 的内容,但它看起来没有记录或完整,还有关于拓扑的讨论,但我找不到任何相关信息。

我该怎么做才能完成这项工作?我正在使用 castle windsor 集成并通过 ep.LoadFrom(container);

加载我的命令处理程序

[更新]

我可以使用以下方法获取消息的基础类型:

var type = cmd.Body.GetType();

是否可以使用该类型作为通用参数:

this._commandBus.Send(cmd.Body).Wait();

我猜是题?

如果您知道底层消息类型,您可以使用context.TryGetPayload<T> 来检索您需要的对象。

如果您有来自数据库的具体对象,并且正在正确反序列化它,请在 MassTransit 中使用 Sendobject 重载,而不是使用接口重载。通过将其设为对象,MassTransit 将在运行时确定类型,并使用匹配的序列化程序来获取实际对象类型,而不是指定的接口类型。