English 中文(简体)
How to configure nservicebus msmqtransport with code
原标题:

I m just geting started with NServiceBus and can t figure out what I m missing when configuring the MsmqTransport in code. If I configure the publisher like this;

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

and the app.config like so


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

Then all works fine - it will create the queues and I can happily message away, however if I delete the queues and then try again with code like so;

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));

The messages seem to get lost as they do not appear in any queues nor get handled - I m guessing I m missing something but I can t see where.

问题回答

D Oh! Post a question that you ve been puzzeling over for a while and take a break. Then of course the answer hits you and it s totaly obvious! I was forgetting to configure the MsmqTransport, my working code is below for anyone that s 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));





相关问题
synchronized message with nservicebus

I have a web service that needs to make a call to nservicebus in a synchronized manner. How can this be achieved ?

How do I correctly pool multiple message in NServiceBus?

I have an NServiceBus app which receives a particular message when a large database update is required. While this update is happening, I want to either somehow ignore all incoming messages of this ...

NServiceBus - Application as subscriber and worker service

I have a service which needs to run on multiple machines picking jobs off of a single queue ensuring each job is only undertaken by a single service. I also need to publish messages for all services ...

Server architecture question. (WCF+NServiceBus)

First of all i will describe current state: Server consists of several WCF services, hosted in one or several win services on diffirent machines. Service responsible for recieving data from ...

MSMQ Access issue in NServiceBus with asp.net web service

I am trying to implement publisher - subscribe in my project of asp.net (wcf) web services. When i am trying to create bus in global.asax protected void Application_Start(object sender, EventArgs e)...

How to configure nservicebus msmqtransport with code

I m just geting started with NServiceBus and can t figure out what I m missing when configuring the MsmqTransport in code. If I configure the publisher like this; IBus bus = Configure.With() ...

Getting the NServiceBus Distributor Sample To Work

I m trying to use the Distributor in the NServiceBus FullDuplex sample but I can t get it working. I ve been following the this guide Getting the NServiceBus Distributor Working, but it doesn t work. ...

热门标签