NServiceBus 中 Bus.Publish 和 Bus.Send 的区别?
使用 Bus.Publish 发布消息和使用 Bus.Send 发送消息有哪些本质区别?我希望了解它们有何不同,以及何时应该选择使用其中一种。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发布用于向多个订阅者通知特定事件。发布端点将具有订阅存储来识别将消息发送到的位置。发送通常用于向端点发出命令。命令告诉端点做某事并且不应该期待回复(尽管有时您确实需要回复并且 NSB 支持这一点)。
您看不到 Send() 目标的原因是您通过配置指定了目标。在您的 app.config 中,您将把消息类型(整个程序集或一个类)映射到目的地。当您这样做时,您不必提供目的地。
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.
Bus.Publish:当您不知道消息的去向(0 到多个订阅者)时使用。
Bus.Send:当您向特定处理程序(客户端到服务器)发送消息时。
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).
通常 Context.Publish() 用于发布事件类型,Context.Send() 用于命令类型
ususally Context.Publish() is for publishing Event Type and Context.Send() is for Command Type