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

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.
主站蜘蛛池模板: 贵定县| 宜宾市| 宣城市| 普陀区| 灌南县| 惠来县| 孝昌县| 黄冈市| 招远市| 阿拉善盟| 夏邑县| 宁武县| 二连浩特市| 正蓝旗| 昌都县| 贺兰县| 九江县| 海原县| 杨浦区| 九台市| 从化市| 龙海市| 日土县| 微山县| 射洪县| 友谊县| 达州市| 北京市| 岱山县| 阿合奇县| 岳西县| 江津市| 赣榆县| 惠安县| 鱼台县| 偃师市| 赣州市| 长沙县| 马山县| 仙游县| 枝江市|