【问题标题】:NServiceBus on ASP.NET 5 cannot find event meta data in unobtrusive modeASP.NET 5 上的 NServiceBus 在不显眼模式下找不到事件元数据
【发布时间】:2015-09-12 23:05:08
【问题描述】:

我正在尝试在 ASP.NET 5 Web 应用程序中使用 NServiceBus。在调用 IBus.Send(purchaseTransactionAddedEvent) 时,其中 purchaseTransactionAddedEvent 的类型为 PurchaseTransactionAddedEvent 在另一个名为 Infrastructure.Contract 的程序集中定义,我收到此错误:

Message=找不到元数据 'Infrastructure.Contract.Events.PurchaseTransactionAddedEvent'。请 确保以下几点: 1. 'Infrastructure.Contract.Events.PurchaseTransactionAddedEvent' 包含在初始扫描中。 2.“Infrastructure.Contract.Events.PurchaseTransactionAddedEvent”实现“IMessage”、“IEvent”或“ICommand”,或者, 如果你不想实现一个接口,你可以使用'Unobtrusive 模式'。源=NServiceBus.Core

如下配置端点时,我使用的是不显眼模式:

            busConfiguration.UseTransport<AzureServiceBusTransport>();

            // we are using In memory persistence for messages
            busConfiguration.UsePersistence<InMemoryPersistence>();

            // NOTE: this is important and has to be set on publisher and subscriber endpoints.
            // We are using unobstrusive mode, so our messages/events do not have to implement IMessage, IEvent, etc
            var conventionsBuilder = busConfiguration.Conventions();
            conventionsBuilder.DefiningEventsAs(t => t.Namespace != null && t.Namespace == "Infrastructure.Contract.Events");

但这似乎不适用于新的 ASP.NET 5 文件夹排列。

已在 NServiceBus 上启用了日志记录,但它没有告诉我它正在扫描哪些程序集。鉴于 ASP.NET 5 不再有 bin 文件夹,如何解决此问题?

【问题讨论】:

    标签: c# asp.net .net nservicebus


    【解决方案1】:

    Bus.Send 正在寻找命令,而不是事件。事件通过 Bus.Publish 发布。但是你should not send/publish events from a website。首先向处理程序发送命令,并让处理程序发布事件。更多信息请查看this article

    试试这个

    var configuration = new BusConfiguration();
    configuration.UseSerialization<JsonSerializer>();
    configuration.UseContainer<AutofacBuilder>(x => x.ExistingLifetimeScope(container));
    
    ConventionsBuilder conventions = configuration.Conventions();
    conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Infrastructure.Contract") && t.Namespace.EndsWith("Commands"));
    
    Bus = NServiceBus.Bus.CreateSendOnly(configuration);
    

    然后通过 Bus.Send(myCommand) 发送您的命令

    【讨论】:

    • 为什么网络应用不应该发布事件?
    • @JeffDunlop 这能回答你的问题吗? docs.particular.net/nservicebus/hosting/…逻辑发布者是一个很重要的原因。
    • “不应该”和“应该避免”是完全不同的东西;感谢您的链接。
    • 基于您提供的从 Web 应用程序发布的链接只需要您考虑某些准则,尤其是对于 NServiceBus 5+。
    • 另一件事,恢复到 ASP.NET 5 并且可以跨两个 ASP.NET 5 应用程序发送和接收命令。但是,在一个上发布的事件不能被另一个接收。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2012-01-08
    • 1970-01-01
    相关资源
    最近更新 更多