You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Arbi Akhina <ar...@gmail.com> on 2015/04/21 20:15:19 UTC

Fwd: Not receiving remove events on PathChildrenCache

I'm using Apache Curator for service discovery, and PathChildrenCache to
listen for events when a service is added/updated/deleted.

PathChildrenCache pathCache = new PathChildrenCache(client, "/directory", true);
pathCache.getListenable().addListener(new PathChildrenCacheListener() {
  @Override
  public void childEvent(CuratorFramework client,
PathChildrenCacheEvent event) throws Exception {
    if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
      System.out.println("Added");
    }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
      System.out.println("Updated");
    }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
      System.out.println("Removed");
    }
  }}
pathCache.start();

When I register a service through
org.apache.curator.x.discovery.ServiceDiscovery, I got an added event. But
when I un-register a service I don't get the removed event.

How I could properly listen to service events?

Re: Not receiving remove events on PathChildrenCache

Posted by Arbi Akhina <ar...@gmail.com>.
Hi,

I tried with *ServiceCacheListener* (under the hood it uses a
*PathChildrenCache*).
But it sounds like you need to create a service cache for each service you
have to receive events related to this service instances !!!!

Bests,



On Wed, Apr 22, 2015 at 10:33 AM, Arbi Akhina <ar...@gmail.com> wrote:

> @Jordan I'll try with the ServiceCacheListener (didn't see it before :(
> @Scott yeah the node is removed from ZK but no event is triggered, I
> didn't try with TreeCache
>
> On Tue, Apr 21, 2015 at 8:18 PM, Scott Blum <dr...@gmail.com> wrote:
>
>> Hi Arbi,
>>
>> Is the node actually removed in ZK that you're expecting the event for?
>> Also, if you try it with TreeCache, do you get the removal event?
>>
>> On Tue, Apr 21, 2015 at 2:15 PM, Arbi Akhina <ar...@gmail.com>
>> wrote:
>>
>>> I'm using Apache Curator for service discovery, and PathChildrenCache to
>>> listen for events when a service is added/updated/deleted.
>>>
>>> PathChildrenCache pathCache = new PathChildrenCache(client, "/directory", true);
>>> pathCache.getListenable().addListener(new PathChildrenCacheListener() {
>>>   @Override
>>>   public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
>>>     if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
>>>       System.out.println("Added");
>>>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
>>>       System.out.println("Updated");
>>>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
>>>       System.out.println("Removed");
>>>     }
>>>   }}
>>> pathCache.start();
>>>
>>> When I register a service through
>>> org.apache.curator.x.discovery.ServiceDiscovery, I got an added event.
>>> But when I un-register a service I don't get the removed event.
>>>
>>> How I could properly listen to service events?
>>>
>>>
>>
>

Re: Not receiving remove events on PathChildrenCache

Posted by Arbi Akhina <ar...@gmail.com>.
@Jordan I'll try with the ServiceCacheListener (didn't see it before :(
@Scott yeah the node is removed from ZK but no event is triggered, I didn't
try with TreeCache

On Tue, Apr 21, 2015 at 8:18 PM, Scott Blum <dr...@gmail.com> wrote:

> Hi Arbi,
>
> Is the node actually removed in ZK that you're expecting the event for?
> Also, if you try it with TreeCache, do you get the removal event?
>
> On Tue, Apr 21, 2015 at 2:15 PM, Arbi Akhina <ar...@gmail.com>
> wrote:
>
>> I'm using Apache Curator for service discovery, and PathChildrenCache to
>> listen for events when a service is added/updated/deleted.
>>
>> PathChildrenCache pathCache = new PathChildrenCache(client, "/directory", true);
>> pathCache.getListenable().addListener(new PathChildrenCacheListener() {
>>   @Override
>>   public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
>>     if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
>>       System.out.println("Added");
>>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
>>       System.out.println("Updated");
>>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
>>       System.out.println("Removed");
>>     }
>>   }}
>> pathCache.start();
>>
>> When I register a service through
>> org.apache.curator.x.discovery.ServiceDiscovery, I got an added event.
>> But when I un-register a service I don't get the removed event.
>>
>> How I could properly listen to service events?
>>
>>
>

Re: Not receiving remove events on PathChildrenCache

Posted by Scott Blum <dr...@gmail.com>.
Hi Arbi,

Is the node actually removed in ZK that you're expecting the event for?
Also, if you try it with TreeCache, do you get the removal event?

On Tue, Apr 21, 2015 at 2:15 PM, Arbi Akhina <ar...@gmail.com> wrote:

> I'm using Apache Curator for service discovery, and PathChildrenCache to
> listen for events when a service is added/updated/deleted.
>
> PathChildrenCache pathCache = new PathChildrenCache(client, "/directory", true);
> pathCache.getListenable().addListener(new PathChildrenCacheListener() {
>   @Override
>   public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
>     if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
>       System.out.println("Added");
>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
>       System.out.println("Updated");
>     }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
>       System.out.println("Removed");
>     }
>   }}
> pathCache.start();
>
> When I register a service through
> org.apache.curator.x.discovery.ServiceDiscovery, I got an added event.
> But when I un-register a service I don't get the removed event.
>
> How I could properly listen to service events?
>
>

Re: Fwd: Not receiving remove events on PathChildrenCache

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
ServiceDiscovery has its own listener: ServiceCacheListener - use that.

-Jordan



On April 21, 2015 at 1:17:10 PM, Arbi Akhina (arbi.akhina@gmail.com) wrote:

I'm using Apache Curator for service discovery, and PathChildrenCache to listen for events when a service is added/updated/deleted.


PathChildrenCache pathCache = new PathChildrenCache(client, "/directory", true);
pathCache.getListenable().addListener(new PathChildrenCacheListener() {
  @Override
  public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
      System.out.println("Added");
    }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
      System.out.println("Updated");
    }else if(event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
      System.out.println("Removed");
    }
  }
}
pathCache.start();
When I register a service through org.apache.curator.x.discovery.ServiceDiscovery, I got an added event. But when I un-register a service I don't get the removed event.

How I could properly listen to service events?