新手在这里需要帮助。
我一直在查看自定义配置文档。但是,我无法弄清楚缺少什么,或者我是否走在正确的道路上。我正在尝试使用 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.
对于像我这样的新手来说,任何指针、建议和评论都非常受欢迎。先感谢您。