[英]Pub-Sub Design Pattern
I've got two projects: one of them is a multi-processor project and the second is a single processor. 我有两个项目:其中一个是多处理器项目,第二个是单个处理器。 Both of them are written in Node JS.
它们都是用Node JS编写的。
In addition, I'm using three systems - which are: Loggly, Mixpanel, e-Mail system. 另外,我正在使用三个系统-Loggly,Mixpanel,电子邮件系统。 There are some events which are relevant to both projects - such as transaction of some products.
有些事件与两个项目都有关-例如某些产品的交易。
Once a transaction event happens - I need to do three main things: 1) Update Loggly about the transaction properties. 一旦发生交易事件-我需要做三件事:1)更新Loggly有关交易属性的信息。 2) Update Mixpanel about the transaction properties.
2)更新有关事务属性的Mixpanel。 3) Update e-Mail system (for example - to send a confirmation mail about the transaction).
3)更新电子邮件系统(例如-发送有关交易的确认邮件)。
The data is sent by JSON format. 数据以JSON格式发送。
In addition, some of the events are relevant for all three systems (Loggly, Mixpanel, eMail system), and some are relevant only for a part of them. 此外,某些事件与所有三个系统(Loggly,Mixpanel,电子邮件系统)有关,而某些事件仅与其中一部分有关。
Each system is interested in a different part of the data. 每个系统都对数据的不同部分感兴趣。 For example, some systems need all the data while others are using only a small part of the event's data.
例如,某些系统需要所有数据,而其他系统仅使用事件数据的一小部分。
The Question: Currently, in my project - once an event occurs - I'm sending directly the data from the two projects to the relevant systems. 问题:当前,在我的项目中-一旦发生事件-我将直接将数据从两个项目发送到相关系统。 That means that my code is duplicate in 2 projects (and that's bad).
这意味着我的代码在2个项目中重复了(很糟糕)。
For example: 例如:
// call when transaction event happens
function foo(transactionData) {
Loggly.send('Transaction', transactionData);
Mixpanel.send('Transaction', transactionData);
}
I'm looking for new architecture - which can solve the code duplication problem. 我正在寻找可以解决代码重复问题的新体系结构。 What is the best architecture of doing this - combining Pub-Sub pattern and AWS tools?
做到这一点的最佳架构是什么-结合Pub-Sub模式和AWS工具?
What is the right way of doing this? 正确的做法是什么?
Thanks for your help. 谢谢你的帮助。
Since you are working with AWS, I suggest learning more about Amazon SNS https://aws.amazon.com/pub-sub-messaging/ 由于您正在使用AWS,因此建议您了解有关Amazon SNS的更多信息https://aws.amazon.com/pub-sub-messaging/
You can set up a "Topic" on SNS which will then fan out messages to any services subscribed to it. 您可以在SNS上设置“主题”,然后将其散发到订阅了该服务的任何消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.