0

I am using distributed ehcache with terracotta on two servers. In my cache manager I have multiple caches. But now I have a requirement that whenever an element is added into 1 particular cache on 1 server , I want to get notified of that put on second server. I tried using CacheEventListener but that works locally. Could you please help in figuring out what can I do. Can I use replication mechanism together with terracotta to solve this problem, as by using replication on 1 cache I will get that element on other server and for all other caches I can use terracotta. Please help it is very urgent. thanks in advance

user1147070
  • 491
  • 7
  • 21

1 Answers1

0

CacheEventListener CAN work only locally, but you can configure it to work over the cluster via Terracotta as well using the listenFor property. It can take the following values:

  • all - the default is to deliver all local and remote events
  • local - deliver only events originating in the current node
  • remote - deliver only events originating in other nodes

Check the documentation at http://ehcache.org/documentation/apis/cache-event-listeners

Hope this helps!

Update: It turns out that you need another CacheEventListener to make events distributed over the cluster. Your configuration will look similar to this:

<cache name="myCache"
       ...
       <cacheEventListenerFactory class="net.sf.ehcache.event.TerracottaCacheEventReplicationFactory" properties="" listenFor="all"/>
       <cacheEventListenerFactory class="foo.bar.MyListenerFactory" properties="" listenFor="all"/>
       <terracotta/>
</cache>
Jaza
  • 86
  • 3
  • could you please tell me how can i configure it to use over the cluster? Like i ma using my own cacheEventListener and it is not replicating the events over other nodes in the cluster. – user1147070 Jan 02 '13 at 09:54
  • How did you configure your CacheEventListener? Something like that should work: ... – Jaza Jan 07 '13 at 10:33
  • yes i have configured it the same way.. but it is not replicating events on the other instance. – user1147070 Jan 08 '13 at 06:31
  • It seems you are right. I did some further research, looks like you have to also add another CacheEventListenerFactory: . I will update the response. – Jaza Jan 08 '13 at 09:58