Using version 2.0.0.1219
I am attempting to self host both a subscriber and publisher with NServiceBus and VS2010. The programs run and initialize but I cannot get the messages to move across. The publisher acts like it is posting, no errors, but the subscriber receives nothing.
Here is the subscriber config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
</configSections>
<!-- in order to configure remote endpoints use the format: "queue@machine"
input queue must be on the same machine as the process feeding off of it.
error queue can (and often should) be on a different machine.
-->
<MsmqTransportConfig InputQueue="loads" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="NServiceMessage" Endpoint="loads"/>
</MessageEndpointMappings>
</UnicastBusConfig>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
And the publisher config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
</configSections>
<MsmqTransportConfig InputQueue="loads" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
<!-- publishers don't need to set this for their own message types -->
<!--<add Messages="Messages" Endpoint="messagebus" />-->
</MessageEndpointMappings>
</UnicastBusConfig>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Here is the publisher code:
class Program
{
private static IBus _serviceBus;
static void Main(string[] args)
{
_serviceBus = Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqSubscriptionStorage()
.MsmqTransport()
.UnicastBus()
.LoadMessageHandlers()
.CreateBus()
.Start();
while (true)
{
Console.WriteLine("Press a key to send data.");
Console.ReadKey();
SendMessaage();
}
}
private static void SendMessaage()
{
LoadMessage message = GetNextMessage();
_serviceBus.Publish(message);
}
private static LoadMessage GetNextMessage()
{
LoadMessage result = new LoadMessage();
result.DeliveryDate = DateTime.Today.AddDays(3).ToShortDateString();
result.DestinationCity = "Boise";
result.DestinationCountry = "USA";
result.DestinationState = "ID";
result.EventId = Guid.NewGuid();
result.Time = DateTime.Now.ToUniversalTime();
result.OriginState = "OR";
result.OriginCity = "Portland";
result.OriginCountry = "USA";
result.EquipmentID = 3;
return result;
}
}
And the subscriber code
class Program
{
private static IBus _serviceBus;
private static LoadMessageHandler _messageHandler;
static void Main(string[] args)
{
_messageHandler = new LoadMessageHandler();
_serviceBus = Configure
.With()
.Log4Net()
.DefaultBuilder()
.BinarySerializer()
.MsmqSubscriptionStorage()
.MsmqTransport()
.UnicastBus()
.LoadMessageHandlers()
.CreateBus()
.Start();
Console.ReadKey();
}
}
And the message code
public class LoadMessageHandler : IHandleMessages<LoadMessage>
{
public void Handle(LoadMessage message)
{
Console.WriteLine(String.Format("GUID: {0}", message.EventId));
}
}
More problems:
1: The msmq transport must be configured as transactional for the publisher to accept subscription messages. See http://blogs.planbsoftware.co.nz/?p=234 for an example of configuring these.
2: Publisher is using XmLSerializer and subscriber is using BinarySerializer, which makes them incompatible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With