简体   繁体   English

用于了解pub-sub消息是否成功的模式

[英]Patterns for knowing if a pub-sub message was successful

I'm developing microservices for a project and we're experimenting with pub-sub communication using AWS SNS+SQS. 我正在为一个项目开发微服务,我们正在尝试使用AWS SNS + SQS进行pub-sub通信。 We're unsure how to signal to services whether or not other services have successfully completed tasks or not. 我们不确定如何向服务发出信号,无论其他服务是否成功完成任务。
For example, if service A emits an SNS Event and service D, E, and F all are listening to the subscribed SQS Queue, how does service A know if the activities kicked off by service A inside of service D, E, and F were successful? 例如,如果服务A发出SNS事件并且服务D,E和F都在监听订阅的SQS队列,那么服务A如何知道服务A,服务D,E和F内的服务A启动的活动是成功?

I'll give a more concrete example: A new user registers for a website. 我将举一个更具体的例子:一个新用户注册一个网站。 This network call first reaches the user service in the backend. 该网络呼叫首先到达后端的user service If the user was successful, it sends off an event saying a new user was created. 如果用户成功,则会发送一个表示已创建新用户的事件。 That triggers the email service to send an email to for the user to confirm his registration. 这会触发email service发送电子邮件给用户以确认其注册。 What happens if it fails to send an email? 如果它无法发送电子邮件会怎么样? Has the user service : user service

1) Already responded to the frontend saying it was successful 1)已经回应了前端说它成功了

2) Or is it waiting for a confirmation? 2)还是在等待确认? What is a good pub-sub pattern for confirmations? 什么是确认的好的pub-sub模式?

I know we could have just done a synchronous call, but this example is simplified for brevity's sake. 我知道我们可以做一个同步调用,但为了简洁起见,这个例子是简化的。

As @dbugger says in the comments, you can have the subscribers send an ack or something back the publisher. 正如@dbugger在评论中所说,您可以让订阅者向发布者发送回复或其他内容。

However, it is the publisher's responsibility to ensure the events were received by the subscribers? 但是,出版商有责任确保订阅者收到活动吗?

Kind of the point of publishing events is that the publisher doesn't (and shouldn't) need to know about the state of consumers subscribing to the event, whether the subscribers ignored the message, or even if there are no subscribers. 发布事件的重点在于发布者不需要(也不应该)知道订阅该事件的消费者的状态,订阅者是否忽略该消息,或者即使没有订阅者。

If the publisher does need to know, then rather than an event, the publisher should be sending a command direct to the consumer in a request-response pattern, rather than an event. 如果发布者确实需要知道,那么发布者应该以请求 - 响应模式而不是事件直接向消费​​者发送命令,而不是事件。

This is because a command message assumes knowledge of the recipient whereas an event message assumes no knowledge. 这是因为命令消息假设接收者的知识,而事件消息假定不知道。

In terms of knowing from a top-down perspective when an event has arrived: well, you should be using a durable message transport which can guarantee delivery of your event, but even with durability you can still drop messages. 在事件到达时从自上而下的角度了解:嗯,您应该使用持久的消息传输来保证事件的传递,但即使有耐用性,您仍然可以丢弃消息。

The only real way of doing it is to implement some kind of instrumentation which allows you to track the "conversations" which are encoded in the events being published from place to place. 唯一真正的做法是实现某种仪器,它允许您跟踪在各地发布的事件中编码的“对话”。 There are tools available for this (I have only used one, for NServicebus called ServicePulse ). 有可用的工具(我只使用了一个,NServicebus称为ServicePulse )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM