从nservicebus版本3升级到版本4,并收到以下错误消息
“未配置消息序列化程序。”
堆栈跟踪:
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Unicast \ UnicastBus.cs中的NServiceBus.Unicast.UnicastBus.ValidateConfiguration():第866行
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Unicast \ UnicastBus.cs中的NServiceBus.Unicast.UnicastBus.Start(Action startupAction):第739行
at NServiceBus.Unicast.UnicastBus.Start()in c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Unicast \ UnicastBus.cs:line 718
在D:\ dev \ backup \ soa_cyclemonkey \ Inventory \ Inventory.CreateOrder \ IT_OPS \ CustomInit.cs中的CycleMonkey.Inventory.CreateOrder.IT_OPS.CustomInit.Init():第20行
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Hosting \ Configuration \ ConfigurationManager.cs中的NServiceBus.Hosting.Configuration.ConfigManager.ConfigureCustomInitAndStartup():第43行
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Hosting \ GenericHost.cs中的NServiceBus.Hosting.GenericHost.PerformConfiguration():第126行
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Hosting \ GenericHost.cs中的NServiceBus.Hosting.GenericHost.Start():第29行
位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ hosting \ NServiceBus.Hosting.Windows \ WindowsHost.cs中的NServiceBus.Hosting.Windows.WindowsHost.Start():第56行
at NServiceBus.Hosting.Windows.Program。<> c_ DisplayClassd.b _5(WindowsHost服务)位于c:\ TeamCity \ buildAgent \ work \ d4de8921a0aabf04 \ src \ hosting \ NServiceBus.Hosting.Windows \ Program.cs:第76行
在Topshelf.Internal.ControllerDelegates 1.StartActionObject(Object obj) in c:\Projects\TopShelfForNSB\src\Topshelf\Internal\ControllerDelegates.cs:line 18
at Topshelf.Internal.IsolatedServiceControllerWrapper
1.<> c_ DisplayClass2.b _1(TService服务)在c:\ Projects \ TopShelfForNSB \ src \ Topshelf \ Internal \ IsolatedServiceControllerWrapper.cs :第65行
在Topshelf.Internal.ServiceController 1.<.cctor>b__1(ServiceController
1 sc)c:\ Projects \ TopShelfForNSB \ src \ Topshelf \ Internal \ ServiceController.cs:第35行
在Magnum.StateMachine.LambdaAction 1.Execute(T instance, Event event, Object parameter) in :line 0
at Magnum.StateMachine.EventActionList
1.Execute(T stateMachine,Event event,Object parameter)in:line 0
升级中是否遗漏了某些内容?正在运行的代码版本3:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
}
public class CustomInit : IWantCustomInitialization
{
public void Init()
{
Configure.Instance
.CastleWindsorBuilder()
.DefaultBuilder()
.Sagas()
.RunTimeoutManagerWithInMemoryPersistence()
.ConfigureMongoSagaPersister<CreateOrderSagaData>("mongodb://localhost/create-order");
Configure.Instance
.XmlSerializer()
.MsmqSubscriptionStorage()
.MsmqTransport()
.UnicastBus();
}
}
相同代码的第4版,其中包含升级所需的建议更改
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, UsingTransport<Msmq>
{
}
public class CustomInit : IWantCustomInitialization
{
public void Init()
{
Configure.Features.Enable<Sagas>();
Configure.Serialization.Xml();
Configure.Instance
.CastleWindsorBuilder()
.UseInMemoryTimeoutPersister()
.ConfigureMongoSagaPersister<CreateOrderSagaData>("mongodb://localhost/create-order");
Configure.Instance
.MsmqSubscriptionStorage()
.UnicastBus()
.CreateBus()
.Start();
}
}
答案 0 :(得分:1)
当引导另一个容器时,使用IWantCustomInitialization接口和IConfigureThisEndpoint,如@JohnSimons提到的那样。
此外,当您在IConfigureThisEndpoint中实现IWantCustomInitialization时,还没有总线,因此此时尚未创建实例,因此您需要使用Configure.With()而不是Configure.Instance。
注意:您不需要指定UsingTransport,因为Msmq是默认传输。 您也不需要指定Configure.Serialization.Xml(),因为Xml是默认的序列化程序。
因此,如果您将代码更改为以下内容,则应该可以正常工作:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
Configure.Features.Enable<Sagas>();
Configure.With()
.CastleWindsorBuilder()
.UseInMemoryTimeoutPersister()
.MsmqSubscriptionStorage();
}
}