NServiceBus: How do I get a subscriber to start processing messing without using generic host?
I am modifying the PubSub sample, and have been playing around with the configuration of NServiceBus. Currently, my EndpointConfig.cs file has configuration like this:
Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) })
.CustomConfigurationSource(new UserConfigurationSource()
.Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 }))
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true);
Now I want to change it to just be a console app without the generic host. Here's what I changed:
- Changed the project output to be Console app
- Changed the startup settings to not invoke the generic host
Moved the configuration above to the Main method like this:
Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) }) 开发者_开发技巧 .CustomConfigurationSource(new UserConfigurationSource() .Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 })) .DefaultBuilder() .XmlSerializer() .MsmqTransport() .IsTransactional(true);
Console.ReadLine();
Is there something else I should be doing to "startup" the subscriber to read messages?
Look at the Async Pages sample to see how to self-host NServiceBus (like in IIS). You're missing .UnicastBus().LoadMessageHandlers().Start().
FYI my config looks something like,
_Bus = NServiceBus.Configure.With()
.DefaultBuilder()
.Log4Net(new MyLogAppender())
.XmlSerializer()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(true)
.UnicastBus()
.ImpersonateSender(false)
.DoNotAutoSubscribe()
.LoadMessageHandlers()
.CreateBus()
.Start();
精彩评论