NServiceBus 5 RabbitMQ的交通引发异常,同时使UnicastBus(NServi

2019-10-21 08:53发布

我试图在自托管方案中使用NServiceBus与RabbitMQ的。 我获得了在GitHub上NServiceBus和NServiceBus.RabbitMQ回购追查到目前为止我有问题的来源,所以我使用的版本是对他们的回购源截至昨日。

下面是我的配置:

        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

这是我的应用程序配置:

<?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>

我缺少的是能够自我主机NServiceBus使用RabbitMQ的运输?

Answer 1:

我刚才吃了这个确切的问题,而解决方法是为安德烈亚斯建议。 我增加了以下我的配置代码...

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

随着到位关于NServiceBus.LocalAddress的错误信息不再出现。 我完全设置如下(代码,然后配置文件)

[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>


Answer 2:

摩根Skinner的回答帮助找出我的问题的实际根源。 我已经添加了建议代码configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);

之后,这个例外是更具描述性的。 NServiceBus.RabbitMQ包会自动下载RabbitMQ.Client包。 后来的一揽子更新到最新的可用上的NuGet,这创造之间的NserviceBus.RabbitMQ期待什么,什么是实际安装的版本冲突。 我已经完全删除这两个软件包并重新安装NserviceBus.RabbitMQ包和错误走了。 该..assembliesToScan ...线不再需要任何。



文章来源: NServiceBus 5 with RabbitMQ transport throwing exception while enabling UnicastBus