2

我的应用程序正在尝试从端点接收事件。
如果我显式订阅<>(),我会在发布端点看到订阅。如果我尝试通过配置约定来获得相同的结果,它会失败。

我错过了什么?

我的配置如下所示:

public Subscriber(int maxConcurrency)
{
    var pingEventType = typeof(IMyEvent);
    var pingHandlerType = typeof(MyEventHandler);

    var busConfiguration = new BusConfiguration();
    busConfiguration.EndpointName("MyEndpointName");
    busConfiguration.UseSerialization<JsonSerializer>();
    busConfiguration.EnableInstallers();
    busConfiguration.UsePersistence<NHibernatePersistence>();
    busConfiguration
        .UseTransport<SqlServerTransport>()
        .CallbackReceiverMaxConcurrency(maxConcurrency);
    busConfiguration.AssembliesToScan(AllAssemblies
        .Matching("NServiceBus")
        .And("ServiceControl")
        .And(pingHandlerType.AssemblyQualifiedName)
        .And(pingEventType.AssemblyQualifiedName));
    busConfiguration
        .Conventions()
        .DefiningEventsAs(x => x.Namespace != null && x.Namespace == pingEventType.Namespace);

    var container = new ContainerBuilder().Build();
    busConfiguration.UseContainer<AutofacBuilder>(customizations =>
    {
        customizations.ExistingLifetimeScope(container);
    });
    _startableBus = Bus.Create(busConfiguration);

    // Uncommenting below line results in subscription on the publishing endpoint
    //_startableBus.Subscribe(pingEventType);
}

最相关的文档和示例代码似乎没有提到我应该做的任何其他事情https://docs.particular.net/nservicebus/messaging/conventions?version=core_5

4

2 回答 2

4

找到了。AssemblyQualifiedName 是以程序集为前缀的类型的名称。我需要的是程序集本身的名称。所以

busConfiguration.AssembliesToScan(AllAssemblies
    .Matching("NServiceBus")
    .And("ServiceControl")
    .And(pingHandlerType.AssemblyQualifiedName)
    .And(pingEventType.AssemblyQualifiedName));

本来应该

busConfiguration.AssembliesToScan(AllAssemblies
    .Matching("NServiceBus")
    .And("ServiceControl")
    .And(pingHandlerType.Assembly.GetName().Name)
    .And(pingEventType.Assembly.GetName().Name));

type.Assmembly.FullName 是让我失望了好几个小时的程序集名称,并附有它的所有版本信息等。那也行不通。

于 2017-05-18T20:34:05.477 回答
1

你有处理程序IMyEvent吗?仅当扫描程序集中的给定事件存在处理程序时,自动订阅才有效。

https://docs.particular.net/nservicebus/messaging/publish-subscribe/controlling-what-is-subscribed?version=core_5#automatic-subscriptions

于 2017-05-18T18:01:34.983 回答