views:

190

answers:

1

In a test project based of the nServiceBus pub/sub sample, I've replace the bus.publish with bus.send in the server. The server sends 50 messages with a 1sec wait after each 5 (ie 10 burst of 5 messages). The client does not get all the messages.

The soln has 3 projects - Server, Client, and common messages. The server and client are hosted via the nServiceBus generic host. Only a single bus is defined.

Both client and server are configured to use StructureMap builder and BinarySerialisation.

Server Endpoint:

public class EndPointConfig : AsA_Publisher, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

Server Code :

for (var nextId = 1; nextId <= 50; nextId++)
{
    Console.WriteLine("Sending {0}", nextId);

    IDataMsg msg = new DataMsg { Id = nextId, Body = string.Format("Batch Msg #{0}", nextId) };
    _bus.SendLocal(msg);
    Console.WriteLine("  ...sent {0}", nextId);

    if ((nextId % 5) == 0)
       Thread.Sleep(1000);
}

Client Endpoint:

public class EndPointConfig : AsA_Client, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

Client Clode:

public class DataMsgHandler : IMessageHandler<IDataMsg>
{
    public void Handle(IDataMsg msg)
    {
         Console.WriteLine("DataMsgHandler.Handle({0}, {1}) - ({2})", msg.Id, msg.Body, Thread.CurrentThread.ManagedThreadId);
     }
}

Client and Server App.Config:

<MsmqTransportConfig InputQueue="nsbt02a" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="">
    <MessageEndpointMappings>
      <add Messages="Test02.Messages" Endpoint="nsbt02a" />
    </MessageEndpointMappings>
</UnicastBusConfig>

All run via VisualStudio 2008.

All 50 messages are sent - but after the 1st or 2nd batch. only 1 msg per batch is sent?

Any ideas? I'm assuming config or misuse but ....?

A: 

Your main problem is that you've configured both processes to use the same input queue. Give each one their own queue.

Udi Dahan