You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Fabrizio Cucci <fa...@gmail.com> on 2015/11/20 20:58:33 UTC
Service Discovery and notifications
Hello everyone,
I'm currently working on a Java project that requires some service discovery and service coordination capabilities and I was thinking about using Curator for those purposes.
One of the main feature I would need is to let one service be notified as soon as another service becomes available. E.g. the service A starts and at a certain point it requires some services B. Instead of repeatedly calling the getInstance method of the ServiceProvider abstraction at regular intervals until the service B becomes available (polling-like policy), it would be nice to get notified as soon as the services B becomes available (i.e. at least one instance has been registered).
Is it something feasible using something like the ServiceCacheListener ?
If yes, would it be the best way to go?
And, out of curiosity, what happens if the service B has been registered before the service A attaches his listener? Does the service A get immediately notified because the service B is immediately available?
Thanks in advance for your help and suggestions,
Fabrizio
Re: Service Discovery and notifications
Posted by Fabrizio Cucci <fa...@gmail.com>.
Thanks Jordan, I'll give it a try!
On 23 November 2015 at 01:25, Jordan Zimmerman <jo...@jordanzimmerman.com>
wrote:
> The cacheChanged() method of ServiceCacheListener is called each time a
> change in registrations is noticed. So, you can just respond to that.
>
> And, out of curiosity, what happens if the service B has been registered
> before the service A attaches his listener?
>
>
> Your listener will not get any notifications. However, the ServiceCache
> always has a view of the registered instances so you can iterate over it to
> get the info you want.
>
> -Jordan
>
> On Nov 20, 2015, at 2:58 PM, Fabrizio Cucci <fa...@gmail.com>
> wrote:
>
> Hello everyone,
>
> I'm currently working on a Java project that requires some service
> discovery and service coordination capabilities and I was thinking about
> using Curator for those purposes.
>
> One of the main feature I would need is to let one service be notified as
> soon as another service becomes available. E.g. the service A starts and at
> a certain point it requires some services B. Instead of repeatedly calling
> the getInstance method of the ServiceProvider abstraction at regular
> intervals until the service B becomes available (polling-like policy), it
> would be nice to get notified as soon as the services B becomes available
> (i.e. at least one instance has been registered).
>
> Is it something feasible using something like the ServiceCacheListener ?
> If yes, would it be the best way to go?
>
> And, out of curiosity, what happens if the service B has been registered
> before the service A attaches his listener? Does the service A get
> immediately notified because the service B is immediately available?
>
> Thanks in advance for your help and suggestions,
> Fabrizio
>
>
>
Re: Service Discovery and notifications
Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
The cacheChanged() method of ServiceCacheListener is called each time a change in registrations is noticed. So, you can just respond to that.
> And, out of curiosity, what happens if the service B has been registered before the service A attaches his listener?
Your listener will not get any notifications. However, the ServiceCache always has a view of the registered instances so you can iterate over it to get the info you want.
-Jordan
> On Nov 20, 2015, at 2:58 PM, Fabrizio Cucci <fa...@gmail.com> wrote:
>
> Hello everyone,
>
> I'm currently working on a Java project that requires some service discovery and service coordination capabilities and I was thinking about using Curator for those purposes.
>
> One of the main feature I would need is to let one service be notified as soon as another service becomes available. E.g. the service A starts and at a certain point it requires some services B. Instead of repeatedly calling the getInstance method of the ServiceProvider abstraction at regular intervals until the service B becomes available (polling-like policy), it would be nice to get notified as soon as the services B becomes available (i.e. at least one instance has been registered).
>
> Is it something feasible using something like the ServiceCacheListener ?
> If yes, would it be the best way to go?
>
> And, out of curiosity, what happens if the service B has been registered before the service A attaches his listener? Does the service A get immediately notified because the service B is immediately available?
>
> Thanks in advance for your help and suggestions,
> Fabrizio