views:

114

answers:

2

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));
    }
}
+3  A: 

You seem to use the same input queue for both endpoints, move you subscriber to it's own queue and see if that works.

Also configuring a subscription storage for you subscriber isn't needed as it's the publisher that is responsible for storing subscription info.

Hope this helps!

Andreas
Thanks, it is the first half of what I got wrong.
Steve
+2  A: 

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.

Cirdec
Thanks, that did it, it is the second half of what I got wrong.
Steve