Не удается заставить собственный хост работать на NServiceBus

Использование версии 2.0.0.1219

Я пытаюсь самостоятельно разместить как подписчика, так и издателя с помощью NServiceBus и VS2010. Программы запускаются и инициализируются, но я не могу заставить сообщения перемещаться. Издатель ведет себя так, будто публикует, ошибок нет, но подписчик ничего не получает.

Вот конфиг подписчика

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

И конфиг издателя

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

Вот код издателя:

    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;
    }
}

И код подписки

    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();
    }
}

И код сообщения

public class LoadMessageHandler : IHandleMessages<LoadMessage>
{
    public void Handle(LoadMessage message)
    {
        Console.WriteLine(String.Format("GUID: {0}", message.EventId));
    }
}

person Steve    schedule 25.08.2010    source источник
comment
Для определения причины этой проблемы требуется более полный код, включая пространства имен и целевые библиотеки DLL. NServiceMessage в ‹add Messages=NServiceMessage Endpoint=loads/› относится к dll, в которой определен тип LoadMessage.   -  person Cirdec    schedule 25.08.2010


Ответы (2)


Больше проблем:

1: транспорт msmq должен быть настроен как транзакционный, чтобы издатель мог принимать сообщения подписки. См. http://blogs.planbsoftware.co.nz/?p=234. для примера их настройки.

2: издатель использует XmLSerializer, а подписчик использует BinarySerializer, что делает их несовместимыми.

person Cirdec    schedule 25.08.2010
comment
Спасибо, что сделал это, это вторая половина того, что я ошибся. - person Steve; 25.08.2010

Кажется, вы используете одну и ту же входную очередь для обеих конечных точек, перемещаете подписчика в свою собственную очередь и смотрите, работает ли это.

Кроме того, настройка хранилища подписки для вашего подписчика не требуется, поскольку именно издатель отвечает за хранение информации о подписке.

Надеюсь это поможет!

person Andreas Öhlund    schedule 25.08.2010