简体   繁体   English

Spring如何同步两个微服务

[英]Spring how to sync two microservices

I have two microservices.我有两个微服务。 Service #1 puts a certain object in the queue (a table in the database) that needs to be processed. Service #1将某个对象放入需要处理的队列(数据库中的一个表)中。 After that, in service #2 , the sheduler takes new records from the queue every few seconds and processes them, and then saves the result as json to the database.之后,在service #2 ,调度程序每隔几秒钟从队列中取出新记录并处理它们,然后将结果作为 json 保存到数据库中。 The question is, how do I notify service #1 about the result of processing?问题是,如何将处理结果通知service #1

You can achieve this using any messaging brokers activeMq or rabbitMq.您可以使用任何消息传递代理 activeMq 或 rabbitMq 来实现这一点。 Please refer: https://spring.io/guides/gs/messaging-rabbitmq/ Please make use of a rabbitmq receiver to fetch the notification and trigger the processing on you service 1 appropriately请参考: https ://spring.io/guides/gs/messaging-rabbitmq/ 请使用rabbitmq接收器来获取通知并适当地触发对您服务1的处理

You can set up Kafka for your microservice communication.您可以为您的微服务通信设置 Kafka。 For notifying service #1 you can send an event from service #2 through Kafka.对于通知service #1您可以通过 Kafka 从service #2发送事件。 Suppose, from service #2 you'll send an event named "PROCESSING_DONE" and service #1 will listen to this event and can do the further processing.假设,从service #2发送一个名为“PROCESSING_DONE”的事件, service #1将侦听此事件并可以进行进一步处理。

This all will take place in realtime.这一切都将实时发生。

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

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