2014-12-03 18 views
1

我試圖在自託管方案中使用NServiceBus與RabbitMQ的。我已經在github上獲得了NServiceBus和NServiceBus.RabbitMQ repos的源代碼,以便跟蹤我迄今爲止所遇到的問題,所以我使用的版本是昨天在其回購站中的源代碼。NServiceBus 5 RabbitMQ的交通引發異常,同時使UnicastBus

這裏是我的配置:

 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."} 

繼堆棧它使我看到,它同時使FeatureUnicastBus真實失敗。

這裏是我的應用程序配置:

<?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="[email protected]" /> 
    </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的運輸?

+0

您可以包括NServiceBus.RabbitMQ.dll在assemblyscanning,看看是否可行? – 2014-12-03 21:43:58

+0

與http://stackoverflow.com/questions/29081094/why-is-nservicebus-configuration-broken-after-using-typestoscan相同 – 2015-04-09 08:18:03

回答

2

我剛纔吃了這種確切的問題,而解決方法是爲安德烈亞斯建議。我增加了以下我的配置代碼...

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

摩根斯金納的答案幫助找出我的問題的實際根源。我已經添加了建議代碼configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);

之後,這個例外是更具描述性的。 NServiceBus.RabbitMQ包自動下載RabbitMQ.Client包。後來的軟件包已更新到nuget上的最新版本,並且這個創建的版本與NserviceBus.RabbitMQ預期的版本和實際安裝的版本之間存在衝突。我已經完全刪除了兩個軟件包並重新安裝了NserviceBus.RabbitMQ軟件包,錯誤消失了。 ..assemblyToScan ...行不再需要。