Reactor of event consumers – event traceability

Time:2022-5-7

Reactor of event consumers - event traceability

This article is reproduced from [how to decouple]:https://codedecoupled.com/php…

Reactor andProjectorThe only difference is that we can’t replay reactor’s behavior. Therefore, reactor is a behavior with side effects in the processing field.

So what is the behavior with side effects? If the result of a behavior occurring once is different from that occurring many times, this behavior can be understood as having side effects. For example, sending an email to the user when the order is confirmed has side effects, because when the order is confirmed, the user will receive duplicate emails.

The following are the reactor use cases summarized from our practical experience.

Actual use case

Side effect behavior

Dealing with behaviors with side effects in the field is the most intuitive use case of reactor. For example, send an order email:

Reactor of event consumers - event traceability

Inter aggregation communication

Sometimes two aggregations need to complete a simple process through event communication. At this time, we can use reactor. Suppose we establish two aggregations, order and bill. When the order is confirmed, bill will automatically generate an invoice. We can use reactor to complete the communication between the two aggregations:

Reactor of event consumers - event traceability

There is a reason to emphasize the simplicity of this process. If a process is complex and long-term, we should adopt saga scheme because it supports rollback operation.

Translation domain events

When event traceability is mixed with other architecture modes, we have to deal with cross architecture communication. At this time, we can use reactor. For example, in crud architecture, we also need to listen to domain events in event traceability. If we listen directly in crud, there will be abstract leakage (domain events are abstract concepts in event traceability). At this time, we can use reactor to translate domain events into events in crud and send them:

Reactor of event consumers - event traceability

summary

Reactor is like a special projector. Like projector, it has a single and focused responsibility and is easy to write unit tests.

This article is reproduced from [how to decouple]:https://codedecoupled.com/php…If you are also interested in TDD, DDD and concise code, please follow the official account [how to decouple] to explore the way of software development.

Recommended Today

Simple implementation of snabbdom

webpack.config.js module.exports = { entry: { index: ‘./src/index.js’ }, output: { path: __dirname + ‘/public’, filename: ‘./js/[name].js’ }, devServer: { contentBase: ‘./public’, inline: true } } package.json { “name”: “snabbdom”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: { “test”: “webpack-dev-server –open” }, “keywords”: [], “author”: “”, “license”: “ISC”, “dependencies”: { “snabbdom”: “^3.1.0”, “webpack”: “5”, “webpack-cli”: […]