NServiceBus handler question with messages

I am using NServiceBus as my queuing solution.

I am developing a windows service which is a consumer of messages on the queue (RabbitMQ). These messages are related to requests to provision servers. However, the servers can be different platforms (virtual/physical etc) and as a result, the messages would inherit from different interfaces.

In the Windows Service, i have this line;

    public async Task Handle(MyMessage message, IMessageHandlerContext context)

Could I have seperate handlers for different messages? I am not sure how best to architect this part of the system.

Hi Gurdip,

If I understand what you are saying correctly, you have a number of different message types and each type inherits from a different interface.

To answer your question, yes you can have separate handlers for different messages. Have you had a look at the Saga basics tutorial?

There you can see an example where the ShippingPolicy saga handles both OrderBilled and OrderPlaced messages.

I will check that. Ideally I’d like a single handler (windows service) to handle these types, or is that a bad idea?

That’s a good example as i have a business process that will need a saga (the lifecycle of ordering a server).

Does that saga get hosted in a windows service?

The thing I am wondering is that the server can be virtual or physical so the action for each is different (i.e. the code to provision). I guess my message can have a boolean for if it is virtual or physical and depending on the value, take appropriate steps? And the memory etc can be a sku that links back to the hosting control panel (which hosts the server details).

That approach should be more elegant. I will need to model this out.

Yes, windows services are one ot the options to host a saga.

I’d rather model that using different sagas for different server types. In the beginning it could sound like a lot of duplication. It makes the evolution much simpler when the different types will diverge over time.