Unable to get host to work on NServiceBus

Using version 2.0.0.1219

I am trying to host both the subscriber and the publisher with NServiceBus and VS2010. Programs are started and initialized, but I cannot get messages to move. The publisher acts as if it is a message, no errors, but the subscriber does not receive anything.

Here is the subscriber configuration

<?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 publisher configuration

 <?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 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)); } } 
+6
c # nservicebus servicebus
source share
2 answers

Other problems:

1: The transaction msmq must be configured as transactional for the publisher to accept subscription messages. See http://blogs.planbsoftware.co.nz/?p=234 for an example of how to configure them.

2: The publisher uses the XmLSerializer, and the subscriber uses the BinarySerializer, which makes them incompatible.

+5
source share

It seems you are using the same input queue for both endpoints, move the subscriber to your own queue and see if it works.

Also, you do not need to configure the subscription repository for your subscriber, as he is the publisher responsible for maintaining the subscription information.

Hope this helps!

+5
source share

All Articles