views:

81

answers:

1

When I subscribe as the recipient of a certain type of message using NServiceBus

Bus.Subscribe<MyMessage>()

What am I actually doing? Am I specifying that a particular method on the recipient type will be invoked upon message receipt? If so, within what context does the method run - in a static context, or within the context of a new'd-up parent class instance (and if so, how does NServiceBus know what constructor to use)?

+1  A: 

A message is sent to the publisher telling it "Hi, my name is 'queue@subscriber-machine' and I would like to subscribe to 'MyMessage' events - so send those messages to me when you publish them." The publisher stores this information. When the publisher publishes MyMessage events, those are then put in the subscriber's input queue. On the subscriber side, the message is handled like all others - all the classes which implement IHandleMessage<T> where T is polymorphically compatible with the message are invoked in the appropriate order.

Udi Dahan