tags:

views:

231

answers:

2

I am just starting to play with nservice bus and am trying to get publishing working. I have a listener which seems to be missing some messages. It is configured with

 <MsmqTransportConfig
  InputQueue="InformMessages"
  ErrorQueue="error"
  NumberOfWorkerThreads="5"
  MaxRetries="5"
 />

Interestingly if I set NumberOfWorkerThreads to 1 it consistently misses every other message. For larger values it seems less determinate. In my message handler I have

class MessageHandler : IMessageHandler<ICourseRegister>
{
    public void Handle(ICourseRegister message)
    {
        Console.WriteLine("Message dun got gotted");
        Console.WriteLine("Course name is: " + message.CourseName);
    }

    private IBus bus;
    public IBus Bus
    {
        set { this.bus = value; }
    }
}

and the bus is configured with

        var bus = NServiceBus.Configure.With()
              .SpringBuilder()
              .XmlSerializer()
              .MsmqTransport()
                  .IsTransactional(true)
                  .PurgeOnStartup(false)
              .UnicastBus()
                  .ImpersonateSender(false)
                  .LoadMessageHandlers()
              .CreateBus()
              .Start();

Is there something I need to do and the end of Handler such that it is freed ready to receive the next message or some configuration I need to do so that there is a client side queue to retain messages if the handler is busy. The time between sending messages doesn't seem to matter, it could be 20 seconds and the listener still doesn't get all the messages.

A: 

If you're working similar to the pub/sub sample, what you could be seeing is "polymorphic subscriptions".

In the pub/sub sample, the publisher alternately publishes an interface IEvent and a concrete class EventMessage (which inherits IEvent).

If a subscriber is subscribed to the concrete class, then it won't receive the interface messages. This is true for all kinds of hierarchies, if you subscribe to the specific class, and the publisher publishes a message of the type of its base class, the message won't be dispatched.

The polymorphic subscriptions works the other way around. If you subscribe to the base, any subclass that the publisher publishes will arrive.

This has nothing to do with threading.

Hope that helps.

Udi Dahan
I do not believe that is the case. I am publishing ICourseRegister: bus.Publish<ICourseRegister>(m => m.CourseName = "Swimming 10" + i);And listening for the same class MessageHandler : IMessageHandler<ICourseRegister> { public void Handle(ICourseRegister message) ...If I modify my project to use bus.Send copying the MessageEndpointMappings section from the listener to the publisher every message is received.
stimms
Can you send over your solution so that I can see if the bug can be reproduced?
Udi Dahan
+2  A: 

After taking a look at the solution you sent over, I see what the problem is.

You've specified the same input queue for both processes - the publisher and the subscriber. As a result, you have both processes fighting over the messages which (I think) you intend to be going only to the subscriber.

Give each process its own input queue and everything should be right with the world :-)

Udi Dahan
That was exactly it, thanks.
stimms