What are the essential differences between publishing a message using Bus.Publish and sending a message using Bus.Send? I am looking to understand how they differ and also when I should choose to use one over the other.
3 Answers
Publishing is used to notify multiple Subscribers of a particular event. A Publishing endpoint will have subscription storage to identify where to send messages to. Sending is typically used to issue a command to an endpoint. A command is telling the endpoint to do something and should not expect a reply(although you sometimes do want a reply and NSB supports this).
The reason you do not see a destination for Send() is that you specify the destination via configuration. In your app.config you will map message types(a whole assembly or a class) to a destination. When you do so, you do not have to provide the destination.

- 6,030
- 1
- 23
- 29
-
Thanks Adam - that makes sense not I see role that configuration plays. – Sean Kearon Feb 09 '11 at 07:10
-
Err, the above comment should have read: Thanks Adam - that makes sense now I see role that the configuration plays. – Sean Kearon Jun 07 '11 at 08:23
-
One of the overrides for Bus.Send is Bus.Send(string destination, message), so you can use Bus.Send to send to a specific queue. – RandomUs1r Oct 15 '14 at 22:35
Bus.Publish: used when you don't know where the message is going (0 to many subscribers).
Bus.Send: when you are sending a message to a specific handler (client to server).

- 1,805
- 3
- 17
- 22
-
Okay, but then why do some Send() overloads not have a destination? Confused... – Sean Kearon Feb 08 '11 at 23:13
-
8We take the semantic meaning a bit further. Publish is an event, and we treat events as "hey, something just happened. I don't care what you do with this information, but here you go", where as we treat Bus.Send as commands, which mean "Hey, I need you to do something, and I care about what happens as a result (and therefore know who I am sending it to)" – Matt Mar 05 '14 at 16:35
-
2@SeanKearon Yes, you posted this 4 years ago, but for anyone else. The destination of the send command can be defined in configuration. You don't really want in your code configuration information, so you can use the simpler form of Send() which doesn't take the destination as a parameter if it is defined in your configuration. – XenoPuTtSs Nov 13 '14 at 13:50
ususally Context.Publish() is for publishing Event Type and Context.Send() is for Command Type

- 31
- 4