6

我刚刚开始使用 NServiceBus,无法弄清楚在代码中配置 MsmqTransport 时缺少什么。如果我这样配置发布者;

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

和 app.config 像这样


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

然后一切正常 - 它会创建队列,我可以愉快地发送消息,但是如果我删除队列,然后使用这样的代码重试;

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

这些消息似乎丢失了,因为它们没有出现在任何队列中,也没有得到处理——我猜我错过了一些东西,但我看不到在哪里。

4

1 回答 1

5

哦!发布一个你已经困惑了一段时间的问题,然后休息一下。那么答案当然会打你,这是完全显而易见的!我忘记配置 MsmqTransport,我的工作代码在下面供任何感兴趣的人使用。


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

于 2009-11-18T15:32:02.330 回答