官术网_书友最值得收藏!

Messaging and events

The next step for the Helping Hands application is to define the interactions between the identified microservices. Microservices can either interact by directly sending the messages to other service endpoints synchronously or they can subscribe to the events generated by other microservices and receive the messages asynchronously. Asynchronous messages rely on the underlying message broker and its durability. Message brokers not only help to scale the application by holding the messages yet to be processed in the queue, but also support durable deliveries. Even if a service fails, it can be restored and allowed to start processing pending messages from the point where it left off. Combining both synchronous and asynchronous message patterns for the Helping Hands application gives us a flexible and performant architecture to accomplish a given task, as shown in the following diagram:

All the services of the Helping Hands application must publish change log events related to the business entities on a message queue that can be read by any service that subscribes to it. The published events must be retained by the message queue for a configured amount of time, beyond which the events may be discarded. For example, all the core services—Service Consumer, Service Provider, Service, and Order—publish events on their designated message queues at the allocated topic.

The Lookup Service must subscribe to all the events published by the Consumer, ProviderService, and Order services to maintain a local denormalized database to support search queries. It must add geolocation details by querying the external service and caching the results locally. Any changes done to the consumers, providers, services, and orders databases must be communicated to the Lookup Service via events, asynchronously. The Lookup Service may also publish events to its designated message queue for other services to consume. These events are often useful to analyze the number of search queries received, trending services, and so on.

Services such as Alerting are best suited for such asynchronous messages. The Alerting Service should not only rely on the message broker for various delivery semantics, such as at-least or exactly-once delivery but must also read batches of alerts, combine alerts for the same user and send them as a single consolidated alert.

Services such as Order Service may also rely on direct messages to retrieve details of the consumer, provider, and the service before registering an order for the user. Once the order is registered, a change log event must be published by the Order Service for the Lookup Service to make the order available to be searched.

Event logs are also useful to set up a deep monitoring and reporting infrastructure for microservices. Part-4 of this book describes the monitoring and reporting pattern for the microservices architecture that is based on event logs.
主站蜘蛛池模板: 井陉县| 上高县| 弋阳县| 长乐市| 郁南县| 手游| 邳州市| 开鲁县| 桐庐县| 泰兴市| 柘城县| 民县| 金寨县| 额敏县| 石屏县| 独山县| 麻城市| 金乡县| 张家港市| 台北县| 临西县| 扎鲁特旗| 永新县| 新巴尔虎右旗| 静乐县| 威海市| 江都市| 庆城县| 田东县| 德庆县| 江阴市| 禄丰县| 屏边| 奎屯市| 自治县| 江门市| 阜城县| 蒙自县| 合水县| 瑞昌市| 轮台县|