本文介绍了NServiceBus 5 与 RabbitMQ 传输在启用 UnicastBus 时抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自托管场景中将 NServiceBus 与 RabbitMQ 结合使用.我已经在 github 上获得了 NServiceBus 和 NServiceBus.RabbitMQ 存储库的源代码,以追踪我迄今为止遇到的问题,所以我使用的版本是他们存储库上截至昨天的源代码.

I'm attempting to use NServiceBus with RabbitMQ in a self-hosted scenario. I've obtained the source for the NServiceBus and NServiceBus.RabbitMQ repos on github to track down the issues I've had so far, so the version I'm using is the source on their repos as of yesterday.

这是我的配置:

        var busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("RMAQueue");
        busConfiguration.AssembliesToScan(typeof(RMACommand).Assembly);
        busConfiguration.Conventions()
            .DefiningCommandsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Commands.", StringComparison.Ordinal));
        busConfiguration.Conventions()
            .DefiningEventsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Events.", StringComparison.Ordinal));
        busConfiguration.Conventions()
            .DefiningMessagesAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Messages.", StringComparison.Ordinal));
        busConfiguration.UseTransport<RabbitMQTransport>();
        busConfiguration.Transactions().Disable();
        busConfiguration.PurgeOnStartup(true);
        busConfiguration.UseSerialization<NServiceBus.JsonSerializer>();

        busConfiguration.DisableFeature<SecondLevelRetries>();
        busConfiguration.DisableFeature<StorageDrivenPublishing>();
        busConfiguration.DisableFeature<TimeoutManager>();

        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        var bus = Bus.Create(busConfiguration);

我在 Bus.Create() 行遇到异常:

{"The given key (NServiceBus.LocalAddress) was not present in the dictionary."}

从它的堆栈开始,我发现它在启用 Feature UnicastBus 时失败了.

Following the stack from it leads me to see that it's failing while enabling the Feature UnicastBus.

这是我的应用配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
  </configSections>
  <MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="RMAInterfaces" Endpoint="RMAQueue@localhost" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
  <connectionStrings>
    <add name="NServiceBus/Transport" connectionString="host=localhost" />
    <add name="NServiceBus/Persistence" connectionString="host=localhost"/>
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <!--<AuditConfig
    QueueName="The address to which messages received will be forwarded."
    OverrideTimeToBeReceived="The time to be received set on forwarded messages, specified as a timespan see http://msdn.microsoft.com/en-us/library/vstudio/se73z7b9.aspx"  />-->
  <AuditConfig QueueName="audit" />
</configuration>

为了能够使用 RabbitMQ 传输自托管 NServiceBus,我缺少什么?

What am I missing to be able to self-host NServiceBus using a RabbitMQ transport?

推荐答案

我刚刚遇到了这个确切的问题,修复方法是 Andreas 建议的.我在我的配置代码中添加了以下内容...

I have just had this exact problem, and the fix is as Andreas suggested. I added the following to my configuration code...

configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);

到位后,关于 NServiceBus.LocalAddress 的错误消息不再显示.我的完整设置如下(代码,然后是配置文件)

With that in place the error message regarding NServiceBus.LocalAddress no longer shows up. My complete setup is as follows (code, then config file)

[TestMethod]
public void TestMethod1()
{
    LogManager.Use<Log4NetFactory>();
    var configuration = new BusConfiguration();
    configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
    configuration.UseSerialization<JsonSerializer>();
    configuration.UseTransport<NServiceBus.RabbitMQTransport>();
    configuration.UsePersistence<InMemoryPersistence>();

    var bus = global::NServiceBus.Bus.Create(configuration);
    bus.Start();
}



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" />
  </configSections>

  <MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />

  <connectionStrings>
    <add name="NServiceBus/Transport" connectionString="host=localhost" />
  </connectionStrings>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Assembly="TestNSBCreation" Endpoint="TestNSBCreation" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="ContactAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="C:\logs\TestNSBCreation.log" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
  </log4net>

</configuration>

这篇关于NServiceBus 5 与 RabbitMQ 传输在启用 UnicastBus 时抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:22