Distributed Messaging and Events
Ignite provides high-performance cluster-wide messaging functionality to exchange data via publish-subscribe and direct point-to-point communication models. Messages can be exchanged in an ordered or unordered fashion. Ordered messages are slightly slower, but when used, Ignite guarantees that messages will be received in the same order they were sent.
Ignite distributed events functionality allows applications to receive notifications when a variety of events occur in the distributed grid environment. You can automatically get notified for task executions, read, write or query operations occurring on local or remote nodes within the cluster. Event notifications can also be grouped together and sent in batches or timely intervals.
Ignite ignite = Ignition.ignite(); IgniteMessaging rmtMsg = ignite.message(ignite.cluster().forRemotes()); // Add listener for ordered messages on all remote nodes. rmtMsg.remoteListen("MyOrderedTopic", (nodeId, msg) -> { System.out.println("Received ordered message [msg=" + msg + ", from=" + nodeId + ']'); return true; // Return true to continue listening. }); // Send ordered messages to remote nodes. for (int i = 0; i < 10; i++) rmtMsg.sendOrdered("MyOrderedTopic", Integer.toString(i), 0);
Ignite ignite = Ignition.ignite(); IgniteMessaging rmtMsg = ignite.message(ignite.cluster().forRemotes()); // Add listener for unordered messages on all remote nodes. rmtMsg.remoteListen("MyUnOrderedTopic", (nodeId, msg) -> { System.out.println("Received unordered message [msg=" + msg + ", from=" + nodeId + ']'); return true; // Return true to continue listening. }); // Send unordered messages to remote nodes. for (int i = 0; i < 10; i++) rmtMsg.send("MyUnOrderedTopic", Integer.toString(i));
Ignite ignite = Ignition.ignite(); // Local listener that listenes to local events. IgnitePredicate<CacheEvent> locLsnr = evt -> { System.out.println("Received local event [evt=" + evt.name() + "]"); return true; // Continue listening. }; // Subscribe to specified cache events occuring on local node. ignite.events().localListen(locLsnr, EventType.EVT_CACHE_OBJECT_PUT, EventType.EVT_CACHE_OBJECT_REMOVED); // Get an instance of named cache. final IgniteCache<Integer, String> cache = ignite.cache("cacheName"); // Generate cache events. for (int i = 0; i < 20; i++) cache.put(i, Integer.toString(i));
Ignite ignite = Ignition.ignite(); // Get an instance of named cache. final IgniteCache<Integer, String> cache = ignite.jcache("cacheName"); // Sample remote filter which only accepts events for keys // that are greater than or equal to 10. IgnitePredicate<CacheEvent> rmtLsnr = evt -> { System.out.println("Received remote event [evt=" + evt.<Integer>key() >= 10 + "]"); return true; // Continue listening. }; // Subscribe to specified cache events on all nodes that have cache running. ignite.events(ignite.cluster().forCacheNodes("cacheName")).remoteListen(null, rmtLsnr, EventType.EVT_CACHE_OBJECT_PUT, EventType.EVT_CACHE_OBJECT_REMOVED); // Generate cache events. for (int i = 0; i < 20; i++) cache.put(i, Integer.toString(i));
Also see messaging examples available on GitHub.
Messaging & Events Features
Feature | Description |
---|---|
Topic Based Messaging |
Ignite distributed messaging allows for topic based cluster-wide communication between all nodes. |
Point-to-Point Messaging |
Ignite messages can be sent to either a group of nodes or to an individual node. |
Ordered vs. Unordered |
Ignite supports ordered and unordered messages. Ordered messages are slightly slower, but when used, Ignite guarantees that messages will be received in the same order they were sent. |
Event Notifications |
Ignite distributed events functionality allows applications to receive notifications when a variety of events occur within the cluster. |
Local vs. Remote Events |
Applications can get notified for task executions, read, write or query operations occurring on local or remote nodes within the cluster. |
Automatic Batching |
Event notifications can be grouped together and sent in batches or timely intervals. |