A way to determine that all local services are registered and available to other services. #1240
-
I am working on a project where there are services 1 that send a "ready" event at their start, service 2 receiving this event should trigger an action from service 1. At the moment, none of the existing hooks allows me to wait for the moment of registration of all services, at least I observe this picture in the server logs. Moreover, it is necessary that the request from service 2 comes to the node of service 1 from where the event was sent. The mechanism for determining the node address is already in the application. But when starting two of these services, I constantly encounter the error that service 2 cannot find service 1. Although the first service sends a ready event inside the started function of the broker configuration, judging by the lifecycle, this is the last available event. At the moment, calling the waitForService function inside service 2 saves, but if there are more services 1, then this solution will stop working, since I cannot specify the name of the node that needs to wait. What can I do or where to look? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
On the surface this sounds like the local registry on the node hosting service 2 hasn't yet updated to include the newly started node/service from which the ready event was sent. That said, it does seem odd that the "ready" event from service 1 would be received by the service 2 node before the node's registry has been updated. Debug logs for both services would certainly be helpful in determining what might be going on. In the meantime, I assume you've reviewed and implemented the following? |
Beta Was this translation helpful? Give feedback.
Again, debug logs and some sample code to really understand the problem would be required to dig in further on this.
Not entirely sure but, using the internal
$services.changed
event might be a solution. Outside of that I think I would try to queue "service 1 ready events" in service 2 instances and use the local registry via the internal service actions to process these queued events only when the service is confirmed to be available. You'd probably want to implement some re-queuing and timeout logic for resiliency but I think some of the supported task mixins could prove useful.