How to configure nservicebus msmqtransport with code

I'm just getting started with NServiceBus and can't figure out what I am missing when setting up MsmqTransport in code. If I configure the publisher as follows:

IBus bus = Configure.With() .CastleWindsorBuilder() .XmlSerializer() .MsmqSubscriptionStorage() .MsmqTransport() .IsTransactional(true) .PurgeOnStartup(false) .UnicastBus() .ImpersonateSender(false) .CreateBus() .Start(); bus.Publish(new Message(DateTime.Now)); 

and app.config is like that

 <configSections> <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" /> </configSections> <MsmqTransportConfig InputQueue="testapps_messagebus" ErrorQueue="testapps_errors" NumberOfWorkerThreads="1" MaxRetries="5" /> 

Then everything works fine - this will create the queues, and I can happily send the message, however, if I delete the queues, and then try again with this code:

 var config = Configure.With() .CastleWindsorBuilder() .XmlSerializer() .UnicastBus() .ImpersonateSender(false) .MsmqSubscriptionStorage(); config .Configurer .ConfigureComponent<MsmqTransport>(NServiceBus.ObjectBuilder.ComponentCallModelEnum.None) .ConfigureProperty(x => x.InputQueue, "testapps_messagebus") .ConfigureProperty(x => x.NumberOfWorkerThreads, 1) .ConfigureProperty(x => x.ErrorQueue, "testapps_errors") .ConfigureProperty(x => x.MaxRetries, 5); IBus bus = config .CreateBus() .Start(); bus.Publish(new Message(DateTime.Now)); 

Messages seem to be lost, because they are not displayed in any queues and are not processed - I assume that I have something missing, but I do not see where.

+6
nservicebus
source share
1 answer

D'oh! Ask a question that you have fun for a while and take a break. Then, of course, the answer strikes you, and it is very obvious! I forgot to set up MsmqTransport, my working code is below for anyone interested.

 Configure config = Configure.With(); config .CastleWindsorBuilder() .XmlSerializer() .MsmqSubscriptionStorage() .MsmqTransport() .IsTransactional(true) .PurgeOnStartup(false) .UnicastBus() .ImpersonateSender(false); config .MsmqSubscriptionStorage() .Configurer .ConfigureComponent(NServiceBus.ObjectBuilder.ComponentCallModelEnum.None) .ConfigureProperty(x => x.InputQueue, "testapps_messagebus") .ConfigureProperty(x => x.NumberOfWorkerThreads, 1) .ConfigureProperty(x => x.ErrorQueue, "testapps_errors") .ConfigureProperty(x => x.MaxRetries, 5); IBus bus = config .CreateBus() .Start(); bus.Publish(new Message(DateTime.Now)); 
+5
source share

All Articles