NserviceBus(版本3.2)自定义配置

时间:2012-05-25 21:51:21

标签: nservicebus nservicebus3

新手需要帮助。

我一直在查看自定义配置文档。但是,我无法弄清楚遗失的是什么,或者我是否在正确的道路上。我正在尝试使用IWantCustomInitialization自定义配置来动态创建消息队列(而不是App.Config)并将消息发送到消息队列。

消息类如下: -

using System;
using NServiceBus;

namespace MyMessage
{
    [Serializable]
    public class EventMessage : ITaskInfo
    {
        public string CustomerName { get; set; }
        public string PrimeKey { get; set; }
        public string JobName { get; set; }
        public Guid JobRunId { get; set; }
    }

    public interface ITaskInfo : IMessage
    {
        string CustomerName { get; set; }
        string PrimeKey { get; set; }
        string JobName { get; set; }
        Guid JobRunId { get; set; }
    }
}

测试应用程序如下: -

using System;
using NServiceBus;
using MyMessage;

namespace TestClient
{
    class DontSubscribe : IConfigureThisEndpoint, AsA_Client,
    IWantCustomInitialization
    {
        public void Init()
        {
            Configure.With()
            .DefineEndpointName("customendpoint")
            .Log4Net()
            .XmlSerializer()
            .DefaultBuilder()
            .MsmqTransport()
            .IsTransactional(true)
            .UnicastBus()
            .LoadMessageHandlers()
            .ImpersonateSender(false)
            .DoNotAutoSubscribe()
            .CreateBus().Start();
        }
    }

    public class Program : IWantToRunAtStartup
    {
        public IBus bus { get; set; }

        public void Run()
        {
            Console.WriteLine("Press enter to send a message.");

            while (Console.ReadLine() != null)
            {
                var msg = bus.CreateInstance<EventMessage>();
                msg.JobName = "JobName";
                msg.JobRunId = Guid.NewGuid();
                msg.PrimeKey = "PrimeKey";

                bus.Send("customendpoint", msg);
            }
        }

        public void Stop()
        {

        }

    }
}

并且,App.config如下: -

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig"
type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
</configSections>

<MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1"
MaxRetries="0"/>

</configuration>

我遇到以下错误: -

2012-05-24 15:33:10,386 [Worker.10] WARN NServiceBus.Unicast.Transport.Transact ional.TransactionalTransport [(null)] <(null)> - Failed raising 'transport messa ge received' event for message with ID=a7a885c5-2487-4049-9c41-2faa604c5767\214 System.InvalidOperationException: No handlers could be found for message type: M yMessage.ITaskInfo__impl at NServiceBus.Unicast.UnicastBus.HandleTransportMessage(IBuilder childBuilde r, TransportMessage msg) in d:\BuildAgent-01\work\nsb.master20\src\unicast\NServ iceBus.Unicast\UnicastBus.cs:line 1254 at NServiceBus.Unicast.UnicastBus.TransportMessageReceived(Object sender, Tra nsportMessageReceivedEventArgs e) in d:\BuildAgent-01\work\nsb.master20\src\unic ast\NServiceBus.Unicast\UnicastBus.cs:line 1171 at System.EventHandler`1.Invoke(Object sender, TEventArgs e) at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.OnTrans portMessageReceived(TransportMessage msg) in d:\BuildAgent-01\work\nsb.master20\ src\impl\unicast\transport\NServiceBus.Unicast.Transport.Transactional\Transacti onalTransport.cs:line 480 
2012-05-24 15:33:10,386 [Worker.10] WARN NServiceBus.Unicast.Transport.Transact ional.TransactionalTransport [(null)] <(null)> - Failed raising 'transport messa ge received' event for message with ID=a7a885c5-2487-4049-9c41-2faa604c5767\214 System.InvalidOperationException: No handlers could be found for message type: MyMessage.ITaskInfo__impl at NServiceBus.Unicast.UnicastBus.HandleTransportMessage(IBuilder childBuilde r, TransportMessage msg) in d:\BuildAgent-01\work\nsb.master20\src\unicast\NServ iceBus.Unicast\UnicastBus.cs:line 1254 at NServiceBus.Unicast.UnicastBus.TransportMessageReceived(Object sender, Tra nsportMessageReceivedEventArgs e) in d:\BuildAgent-01\work\nsb.master20\src\unic ast\NServiceBus.Unicast\UnicastBus.cs:line 1171 at System.EventHandler`1.Invoke(Object sender, TEventArgs e) at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.OnTrans portMessageReceived(TransportMessage msg) in d:\BuildAgent-01\work\nsb.master20\ src\impl\unicast\transport\NServiceBus.Unicast.Transport.Transactional\Transacti onalTransport.cs:line 480 
2012-05-24 15:33:11,290 [Worker.10] ERROR NServiceBus.Unicast.Transport.Transact ional.TransactionalTransport [(null)] <(null)> - Message has failed the maximum number of times allowed, ID=a7a885c5-2487-4049-9c41-2faa604c5767\214.

任何指针,建议和评论都非常受欢迎 我。提前谢谢。

1 个答案:

答案 0 :(得分:1)

我好几天都遇到了这个问题...原来我错过了以下内容:

  • 在发布商的类库中右键单击“属性”
  • 单击“调试”选项卡
  • NServiceBus.Integration添加到命令行参数框。

它为我排序了问题,虽然我不知道为什么。