blob: 8a0a6c918ff3fd785b77f20ff26b10f58aa5670f [file] [log] [blame]
<!--
▄▄▄ ██▓███ ▄▄▄ ▄████▄ ██░ ██ ▓█████ ██▓ ▄████ ███▄ █ ██▓▄▄▄█████▓▓█████
▒████▄ ▓██░ ██▒▒████▄ ▒██▀ ▀█ ▓██░ ██▒▓█ ▀ ▓██▒ ██▒ ▀█▒ ██ ▀█ █ ▓██▒▓ ██▒ ▓▒▓█ ▀
▒██ ▀█▄ ▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄ ▒██▀▀██░▒███ ▒██▒▒██░▄▄▄░▓██ ▀█ ██▒▒██▒▒ ▓██░ ▒░▒███
░██▄▄▄▄██ ▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒░▓█ ░██ ▒▓█ ▄ ░██░░▓█ ██▓▓██▒ ▐▌██▒░██░░ ▓██▓ ░ ▒▓█ ▄
▓█ ▓██▒▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░░▓█▒░██▓░▒████▒ ░██░░▒▓███▀▒▒██░ ▓██░░██░ ▒██▒ ░ ░▒████▒
▒▒ ▓▒█░▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░ ░▓ ░▒ ▒ ░ ▒░ ▒ ▒ ░▓ ▒ ░░ ░░ ▒░ ░
▒ ▒▒ ░░▒ ░ ▒ ▒▒ ░ ░ ▒ ▒ ░▒░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░ ▒░ ▒ ░ ░ ░ ░ ░
░ ▒ ░░ ░ ▒ ░ ░ ░░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
-->
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="canonical" href="https://ignite.apache.org/features/messaging.html" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>Distributed Messaging &amp; Events - Apache Ignite</title>
<!--#include virtual="/includes/styles.html" -->
</head>
<body>
<!--#include virtual="/includes/header.html" -->
<article>
<header>
<div class="container">
<h1>Distributed <strong>Messaging and Events</strong></h1>
</div>
</header>
<div class="container">
<p>
Apache Ignite® provides <b>high-performance cluster-wide messaging</b> 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.
</p>
<p> Ignite <b>distributed events</b> 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.
</p>
<h2>Code Examples:</h2>
<!-- Nav tabs -->
<ul id="messaging-examples" class="nav nav-tabs">
<li><a class="active" href="#messaging-example-ordered" aria-controls="home" data-toggle="tab">Ordered Messaging</a></li>
<li><a href="#messaging-example-unordered" aria-controls="profile" data-toggle="tab">Unordered Messaging</a></li>
<li><a href="#events-example-local" aria-controls="profile" data-toggle="tab">Local Events</a></li>
<li><a href="#events-example-remote" aria-controls="profile" data-toggle="tab">Remote Events</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="messaging-example-ordered">
<pre class="line-numbers"><code class="language-java">
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);
</code></pre>
</div>
<div class="tab-pane" id="messaging-example-unordered">
<pre class="line-numbers"><code class="language-java">
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));
</code></pre>
</div>
<div class="tab-pane" id="events-example-local">
<pre class="line-numbers"><code class="language-java">
Ignite ignite = Ignition.ignite();
// Local listener that listenes to local events.
IgnitePredicate&lt;CacheEvent&gt; 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&lt;Integer, String&gt; cache = ignite.cache("cacheName");
// Generate cache events.
for (int i = 0; i < 20; i++)
cache.put(i, Integer.toString(i));
</code></pre>
</div>
<div class="tab-pane" id="events-example-remote">
<pre class="line-numbers"><code class="language-java">
Ignite ignite = Ignition.ignite();
// Get an instance of named cache.
final IgniteCache&lt;Integer, String&gt; cache = ignite.jcache("cacheName");
// Sample remote filter which only accepts events for keys
// that are greater than or equal to 10.
IgnitePredicate&lt;CacheEvent&gt; rmtLsnr = evt -> {
System.out.println("Received remote event [evt=" + evt.&lt;Integer&gt;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));
</code></pre>
</div>
</div>
<h2>GitHub Examples:</h2>
<p>
Also see <a href="https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/messaging" target="github">messaging examples</a>available on GitHub.
</p>
<h2>Messaging & Events Features</h2>
<table class="table table-bordered table-striped" name="Messaging Features">
<thead>
<tr>
<th width="35%" class="left">Feature</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left">Topic Based Messaging</td>
<td>
<p>
Ignite distributed messaging allows for topic based cluster-wide communication between all nodes.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/messaging" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Point-to-Point Messaging</td>
<td>
<p>
Ignite messages can be sent to either a group of nodes or to an individual node.
</p>
<div class="page-links">
<a href="http://apacheignite.readme.io/docs/messaging" target="docs">Docs for this Feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Ordered vs. Unordered</td>
<td>
<p>
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.
</p>
<div class="page-links">
<a href="http://apacheignite.readme.io/docs/messaging" target="docs">Docs for this Feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Event Notifications</td>
<td>
<p>
Ignite distributed events functionality allows applications to receive notifications when a variety of events occur within the cluster.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/events" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Local vs. Remote Events</td>
<td>
<p>
Applications can get notified for task executions, read, write or query operations occurring on local or remote nodes within the cluster.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/events" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Automatic Batching</td>
<td>
<p>
Event notifications can be grouped together and sent in batches or timely intervals.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/automatic-batching" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</article>
<!--#include virtual="/includes/footer.html" -->
<!--#include virtual="/includes/scripts.html" -->
</body>
</html>