Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Bus.Publish and Bus.Send in NServiceBus?

Tags:

nservicebus

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.

like image 242
Sean Kearon Avatar asked Feb 08 '11 21:02

Sean Kearon


People also ask

What is endpoint in NServiceBus?

An endpoint is a logical component that communicates with other components using messages. Each endpoint has an identifying name, contains a collection of message handlers and/or sagas, and is deployed to a given environment (e.g. development, testing, production).

What is the use of NServiceBus?

NServiceBus is a commercial messaging framework provided by Particular Software. It's built on top of Azure Service Bus and helps developers focus on business logic by abstracting infrastructure concerns. In this guide, we'll build a solution that exchanges messages between two services.


2 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.

like image 117
Adam Fyles Avatar answered Dec 03 '22 14:12

Adam Fyles


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).

like image 29
Gord Avatar answered Dec 03 '22 13:12

Gord