user2015534
user2015534

Reputation: 89

Difference between IMessage, ICommand in NServiceBus?

In NServiceBus we have different message type like IMessage, ICommand, IEvent to communicate between system. What is the difference between IMessage, ICommand,IEvent? What business scenario we should use these types?

Thanks

Upvotes: 1

Views: 1205

Answers (2)

melkio
melkio

Reputation: 101

As explained in the documentation:

Message is the unit of communication for NServiceBus, there are two types of messages:

  1. command is used by one or more senders to ask for a specific action for a specific receiver. No broadcasting supported.
  2. event is used by a single sender to notify many receivers that some action has taken place.

Upvotes: 4

Borys Generalov
Borys Generalov

Reputation: 2345

Bear in mind that in SOA you have 4 message types:

  • Command
  • Event
  • Document Message (DataBus feature in terms of NServiceBus)
  • Request-Reply

As you might have already guessed, the IMessage is handy for Request-Reply scenario, which isn't a command or an event, but a hybrid "message" that behaves in non-standard way. Yet another useful scenarios are: audit trail, reporting progress, heartbeat, timeouts (saga or scheduled recurring tasks) etc. Consider these examples:

  • GetActiveUsersCount/GetActiveUsersCountResult
  • status message: AlmostDone
  • UploadPackageTimeout
  • progress message: PreparingData/ProcessingData/AwaitingConfirmation
  • HeartbeatMessage

Upvotes: 2

Related Questions