blob: 838b7d38a5c0a0afb4b55f1bdd28da21e88ba245 [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>
<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>
<link media="all" rel="stylesheet" href="/css/all.css?v=1514336028">
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css'>
<!--#include virtual="/includes/sh.html" -->
</head>
<body>
<div id="wrapper">
<!--#include virtual="/includes/header.html" -->
<main id="main" role="main" class="container">
<section id="messaging" class="page-section">
<h1 class="first">Distributed Messaging and Events</h1>
<p>
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>
<div class="code-examples">
<div class="page-heading">Code Examples:</div>
<!-- Nav tabs -->
<ul id="messaging-examples" class="nav nav-tabs">
<li class="active"><a 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="brush: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);
</pre>
</div>
<div class="tab-pane" id="messaging-example-unordered">
<pre class="brush: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));
</pre>
</div>
<div class="tab-pane" id="events-example-local">
<pre class="brush: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));
</pre>
</div>
<div class="tab-pane" id="events-example-remote">
<pre class="brush: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));
</pre>
</div>
</div>
</div>
<div class="page-heading">GitHub Examples:</div>
<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>
</section>
<section id="key-features" class="page-section">
<h2>Messaging & Events Features</h2>
<table class="formatted" 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>
</section>
</main>
<!--#include virtual="/includes/footer.html" -->
</div>
<!--#include virtual="/includes/scripts.html" -->
</body>
</html>