我正在尝试发布如下所示的消息
_bus.Publish(new BatchCompleted { BatchId = batch.Id});
并在 BatchCompletedHandler 中处理它:
public class BatchCompletedHandler: IHandleMessages<BatchCompleted>
{
public void Handle(BatchCompleted message)
{
Do Some Stuff...
}
}
每当我尝试发布消息时,我都会收到以下 System.Exception:
Could not find Metadata for 'MyAssembly.BatchCompleted'. Messages need to implement either 'IMessage', 'IEvent' or 'ICommand'. Alternatively, if you don't want to implement an interface, you can configure 'Unobtrusive Mode Messages' and use convention to configure how messages are mapped.
该消息确实实现了 IEvent,如下所示
[Serializable]
public class BatchCompleted : IEvent
{
public int BatchId{ get; set; }
}
我正在使用以下代码配置 NSB
Configure.With(MyAssembly)
消息处理程序位于程序集 MyAssembly 中,消息位于 MyMessagesAssembly 中。
我究竟做错了什么?
最佳答案
NServiceBus 找不到正在使用的消息类型。消息位于单独的程序集中,但配置导致 NSB 仅扫描指定的程序集 (MyAssembly),而不是扫描二进制文件夹中所有程序集的默认行为。
将配置更改为
Configure.With()
将扫描所有程序集并允许 NSB 找到所需的消息类型。
我认为错误信息有点误导!
关于.net - NServiceBus:找不到(消息)的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18981020/