与纯 RabbitMQ 相比,使用 NServiceBus + RabbitMQ 有什么优势?
What are advantages of using NServiceBus + RabbitMQ against pure RabbitMQ?
使用 NServiceBus + RabbitMQ 相对于纯 RabbitMQ 有什么优势?
我想它提供了额外的基础设施。但还有什么?
我会尽量记下要点:
- NServiceBus 处理与其底层传输的所有通信,即 Rabbit
- NServiceBus 有一个干净的 api 来编写您的业务逻辑。
- 如果您想获得一些自定义行为,NServiceBus 很容易扩展。
- NServiceBus处理fault tolerance
的方方面面
- NServiceBus 具有许多功能,例如:
Sagas (long running process management)、
Outbox (reliability with non DTC transports)
The Particular Platform for monitoring, debugging and visualizing
这是否回答了您的问题?
你绝对可以只使用纯 RabbitMQ。你只需要记住几件事。
警告:这个答案会有点非常开玩笑。
首先,您应该从头到尾阅读 Enterprise Integration Patterns 并确保您完全理解。它有 736 页,有点枯燥,但是非常有用的信息。成为 RabbitMQ 所有特性的专家也没有坏处。
然后你只需要决定如何 define messages, how to define message handlers, how to send messages and publish events. Before you get too far you'll want a good logging infrastructure. You'll need to create a message serializer and infrastructure for message routing。您需要在每条业务消息的内容中包含一堆与基础设施相关的元数据。您需要构建一个执行良好并有效使用代理连接的消息出队策略,同时牢记并发需求。
接下来您需要了解如何 retry messages automatically when the handling logic fails, but not too many times. You have to have a strategy for dealing with poison messages, so you'll need to move them aside so your handling logic doesn't get jammed preventing valid messages from being processed. You'll need a way to show those messages that have failed and figure out why, so you can fix the problem. You'll want some sort of alerting options so you know when that happens. It would be nice if that poison message display also showed you where that message came from and what the exception was so you don't need to go digging through log files. After that you'll need to be able to reroute the poison messages back into the queue to try again。如果部署不当,您可能会收到很多失败的消息,因此如果您不必一次重试一条消息,那就太好了。
由于您使用的是 RabbitMQ,消息代理上没有事务,因此幻影消息和重复实体是非常现实的问题。您需要在编写所有消息处理逻辑时牢记幂等性,否则您的 RabbitMQ 消息和数据库实体将开始变得不一致。或者,您可以 design infrastructure to mimic distributed transactions by storing outgoing messaging operations in your business database and then executing the message dispatch operations separately. That results in duplicate messages (by design) so you'll need to deduplicate messages as they come in, which means you need well a well-defined strategy for consistent message IDs 跨系统。要小心,因为任何处理事务和并发的事情都可能非常棘手。
您可能想要做一些 workflow type stuff, where an incoming message starts a process that's essentially a message-driven state machine. Then you can do things like trigger an action once 2 required messages have been received. You'll need to design a storage system for that data. You'll probably also need a way to have delayed messages, so you can do things like the buyer's remorse pattern. RabbitMQ has no way to have an arbitrary delay on a message, so you'll have to come up with a way to implement that。
你可能想要一些 metrics and performance counters on this system to know how it's performing. You'll want some way to be able to have tests on your message handling logic, so if you need to swap out some dependencies to make that work you might want to integrate a dependency injection framework。
因为这些系统本质上是去中心化的,所以很难准确地描绘出您的系统是什么样的。如果您 send a copy of every message to a central location, you can write some code 将所有消息对话缝合在一起,然后您可以使用该数据构建消息流图、序列图等。这种基于实时数据的实时文档对于向经理解释事情至关重要或找出进程未按预期工作的原因。
说到文档,请确保 write a whole lot of it 用于消息队列包装器,否则其他开发人员将很难帮助您维护它。如果您团队中的其他人正在编写它,那么当他们找到另一份工作并离开公司时,您将完全搞砸了。您还需要对已构建的 RabbitMQ 包装器进行大量单元测试。像这样的基础设施代码应该是坚如磐石的。您不希望因丢失消息而导致销售损失或类似情况。
因此,如果您牢记这几点,您完全可以在没有 NServiceBus 的情况下使用纯 RabbitMQ。
希望当你完成后,你的老板不会决定你需要从 RabbitMQ to Azure Service Bus or Amazon SQS 转换。
使用 NServiceBus + RabbitMQ 相对于纯 RabbitMQ 有什么优势? 我想它提供了额外的基础设施。但还有什么?
我会尽量记下要点:
- NServiceBus 处理与其底层传输的所有通信,即 Rabbit
- NServiceBus 有一个干净的 api 来编写您的业务逻辑。
- 如果您想获得一些自定义行为,NServiceBus 很容易扩展。
- NServiceBus处理fault tolerance 的方方面面
- NServiceBus 具有许多功能,例如:
Sagas (long running process management)、
Outbox (reliability with non DTC transports)
The Particular Platform for monitoring, debugging and visualizing
这是否回答了您的问题?
你绝对可以只使用纯 RabbitMQ。你只需要记住几件事。
警告:这个答案会有点非常开玩笑。
首先,您应该从头到尾阅读 Enterprise Integration Patterns 并确保您完全理解。它有 736 页,有点枯燥,但是非常有用的信息。成为 RabbitMQ 所有特性的专家也没有坏处。
然后你只需要决定如何 define messages, how to define message handlers, how to send messages and publish events. Before you get too far you'll want a good logging infrastructure. You'll need to create a message serializer and infrastructure for message routing。您需要在每条业务消息的内容中包含一堆与基础设施相关的元数据。您需要构建一个执行良好并有效使用代理连接的消息出队策略,同时牢记并发需求。
接下来您需要了解如何 retry messages automatically when the handling logic fails, but not too many times. You have to have a strategy for dealing with poison messages, so you'll need to move them aside so your handling logic doesn't get jammed preventing valid messages from being processed. You'll need a way to show those messages that have failed and figure out why, so you can fix the problem. You'll want some sort of alerting options so you know when that happens. It would be nice if that poison message display also showed you where that message came from and what the exception was so you don't need to go digging through log files. After that you'll need to be able to reroute the poison messages back into the queue to try again。如果部署不当,您可能会收到很多失败的消息,因此如果您不必一次重试一条消息,那就太好了。
由于您使用的是 RabbitMQ,消息代理上没有事务,因此幻影消息和重复实体是非常现实的问题。您需要在编写所有消息处理逻辑时牢记幂等性,否则您的 RabbitMQ 消息和数据库实体将开始变得不一致。或者,您可以 design infrastructure to mimic distributed transactions by storing outgoing messaging operations in your business database and then executing the message dispatch operations separately. That results in duplicate messages (by design) so you'll need to deduplicate messages as they come in, which means you need well a well-defined strategy for consistent message IDs 跨系统。要小心,因为任何处理事务和并发的事情都可能非常棘手。
您可能想要做一些 workflow type stuff, where an incoming message starts a process that's essentially a message-driven state machine. Then you can do things like trigger an action once 2 required messages have been received. You'll need to design a storage system for that data. You'll probably also need a way to have delayed messages, so you can do things like the buyer's remorse pattern. RabbitMQ has no way to have an arbitrary delay on a message, so you'll have to come up with a way to implement that。
你可能想要一些 metrics and performance counters on this system to know how it's performing. You'll want some way to be able to have tests on your message handling logic, so if you need to swap out some dependencies to make that work you might want to integrate a dependency injection framework。
因为这些系统本质上是去中心化的,所以很难准确地描绘出您的系统是什么样的。如果您 send a copy of every message to a central location, you can write some code 将所有消息对话缝合在一起,然后您可以使用该数据构建消息流图、序列图等。这种基于实时数据的实时文档对于向经理解释事情至关重要或找出进程未按预期工作的原因。
说到文档,请确保 write a whole lot of it 用于消息队列包装器,否则其他开发人员将很难帮助您维护它。如果您团队中的其他人正在编写它,那么当他们找到另一份工作并离开公司时,您将完全搞砸了。您还需要对已构建的 RabbitMQ 包装器进行大量单元测试。像这样的基础设施代码应该是坚如磐石的。您不希望因丢失消息而导致销售损失或类似情况。
因此,如果您牢记这几点,您完全可以在没有 NServiceBus 的情况下使用纯 RabbitMQ。
希望当你完成后,你的老板不会决定你需要从 RabbitMQ to Azure Service Bus or Amazon SQS 转换。