I have created a standard NServiceBus publish subscribe program. I keep getting the following error when sending a message to my publisher NServicBus host:
No destination specified for message TrackEventPublisher.TrackEventPublisher.InternalMessages.TrackEventMessages. Message cannot be sent. Check the UnicastBusConfig section in your config file and ensure that a MessageEndpointMapping exists for the message type.
Well.... the MessageEndpointMapping exists!
Here is my test console application code I use to test the MessagePublisher class:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Click enter to submit message.");
Console.ReadLine();
string aMessage = "Please Work!!!!!!!!";
MessagePublisher publisher = new MessagePublisher();
publisher.PublishEventMessage(aMessage);
}
}
Here is my message sender class which sends a message to another NServiceBus publish server to be published:
public class MessagePublisher
{
public IBus Bus { get; set; }
public MessagePublisher()
{
BusInitializer.Init();
Bus = BusInitializer.Bus;
}
public void PublishEventMessage(string message)
{
Bus.Send(new TrackEventMessages(message));
}
}
My bus initializer:
class BusInitializer
{
public static IBus Bus { get; private set; }
public static void Init()
{
Bus = NServiceBus.Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.UnicastBus()
.LoadMessageHandlers()
.ImpersonateSender(false)
.CreateBus()
.Start();
}
}
My message class:
namespace TrackEventPublisher.TrackEventPublisher.InternalMessages
{
public class TrackEventMessages : IMessage
{
public string HelloWorldMessage { get; set; }
public TrackEventMessages(string message)
{
HelloWorldMessage = message;
}
}
}
And finally, my configuration for the message publisher:
namespace TrackEventPublisher.PublishManager
{
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
}
}
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig InputQueue="PublishManager" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
<add Messages="TrackEventPublisher.TrackEventPublisher.InternalMessages" Endpoint="TrackEventPublisher" />
</MessageEndpointMappings>
</UnicastBusConfig>
</configuration>
The configuration was created by the NServiceBus auto-generator. The configuration appears to be correct. Does anyone have any idea why I get the InvalidOperationException "No destination specified for message" when sending the message via:
Bus.Send(new TrackEventMessages(message));
Thanks in advance. I have spend waaaay too much time on this one.
* Update **
I may be setting up the Bus incorrectly from my MessagePubliser class. My goal is to instantiate the MessagePublisher class from another application (wpf, console, etc). That is why I am using a BusInitializer class. However, the Bus I am creating does not correlate with my app.config in the MessagePublisher class.
Does anyone have a good idea how to instantiate the MessagePublisher class so my bus recognizes the app.config? Perhaps using IWantToRunAtStartup?