I another possibility to create a continuous query per node in your node
affinity set for the cache and have the continuous query return local
values, like this:

            using (IContinuousQueryHandle<ICacheEntry<Key, Value>>
queryHandle = queueCache.QueryContinuous
                (qry: new ContinuousQuery< Key, Value >(new LocalListener())
{ Local = true },
                 initialQry: new ScanQuery< Key, Value > { Local = true }))
(
                // Perform the initial query to grab all existing elements
                foreach (var item in queryHandle.GetInitialQueryCursor())
                {
                    if (NodeIsPrimaryForThisKey(Key)) // Don’t let backups
get involved
                       handler.Add(item.Key);
                }

// move into steady state management of arriving elements...
)

-----Original Message-----
From: Николай Ижиков [mailto:nizhikov....@gmail.com] On Behalf Of Nikolay
Izhikov
Sent: Monday, May 7, 2018 6:40 PM
To: user@ignite.apache.org
Cc: JP <jopandy...@gmail.com>
Subject: Re: Continuous query - Exactly once based event across multiple
nodes..

Hello, JP.

You should use target node in remote filter.

You should check "Is primary node for some record equal to target node?" in
your filter.
Please, see code below.
You can find related discussion and full example here [1].

    @IgniteAsyncCallback
    public static class RemoteFactory implements
Factory<CacheEntryEventFilter<String, Long>> {
        private final ClusterNode node;

        public RemoteFactory(ClusterNode node) {
            this.node = node;
        }

        @Override
        public CacheEntryEventFilter<String, Long> create() {
            return new CacheEntryEventFilter<String, Long>() {
                @IgniteInstanceResource
                private Ignite ignite;

                @Override
                public boolean evaluate(CacheEntryEvent<? extends String, ?
extends Long> cacheEntryEvent) {
                    Affinity<String> aff = ignite.affinity("myCache");

                    ClusterNode primary =
aff.mapKeyToNode(cacheEntryEvent.getKey());

                    return primary.id().equals(node.id());
                }
            };
        }
    }



[1] https://issues.apache.org/jira/browse/IGNITE-8035


В Вс, 06/05/2018 в 23:33 -0700, JP пишет:
> Using continuous query,
>
> How to achieve event trigger for cache exactly only once per key even
> if continuous query is listening in multiple nodes or multiple listener.
> example:
> 1. Scenario 1:
>  Node A: Start Continuous query
>  Node B: Start Continuous query
>  Node C: Insert or Update or Delete record ex: number from 1 to 100
>
> Expected Output should be as below
>  Node A - 1 ,2,3,4,5....50
>  Node B - 51, 52, 53, 54, ... 100
>  Above output is the expected output. Here, event per key should be
> triggered exactly once across nodes.
>
> Actual Output should be as below
>  Node A - 1 ,2,3,4,5,....100
>  Node B - 1, 2, 3, 4,5 ... 100
>
> If this is not possible in Continuous query, then is there any way to
> achieve this.
>
> 2. Scenario 2:
> To achieve expected output,
>  I am using singleton service per Cluster.
>     Ex: Cluster A
>               - Singleton service with Continuous query for cache
>                 Here problem is, service is running in only one instance.
> How to achieve above output with multiple instance of service?
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Reply via email to