public interface IgniteMessaging extends IgniteAsyncSupport
clusterGroup()
.
Users can send ordered and unordered messages to various topics. Note that same topic name
cannot be reused between ordered and unordered messages. Instance of GridMessaging
is obtained from grid projection as follows:
GridMessaging m = Ignition.ignite().message();
There are 2
ways to subscribe to message listening, local
and remote
.
Local subscription, defined by localListen(Object, IgniteBiPredicate)
method, will add
a listener for a given topic on local node only. This listener will be notified whenever any
node within grid projection will send a message for a given topic to this node. Local listen
subscription will happen regardless of whether local node belongs to this grid projection or not.
Remote subscription, defined by remoteListen(Object, IgniteBiPredicate)
, will add a
message listener for a given topic to all nodes in the projection (possibly including this node if
it belongs to the projection as well). This means that any node within this grid projection can send
a message for a given topic and all nodes within projection will receive listener notification.
sendOrdered(Object, Object, long)
), i.e.
messages will be received in the same order they were sent. Ordered messages have a timeout
parameter associated with them which specifies how long an out-of-order message will stay in a queue,
waiting for messages that are ordered ahead of it to arrive. If timeout expires, then all ordered
messages for a given topic that have not arrived yet will be skipped. When (and if) expired messages
actually do arrive, they will be ignored.Modifier and Type | Method and Description |
---|---|
ClusterGroup |
clusterGroup()
Gets grid projection to which this
GridMessaging instance belongs. |
void |
localListen(Object topic,
IgniteBiPredicate<UUID,?> p)
Adds local listener for given topic on local node only.
|
UUID |
remoteListen(Object topic,
IgniteBiPredicate<UUID,?> p)
Adds a message listener for a given topic to all nodes in the projection (possibly including
this node if it belongs to the projection as well).
|
void |
send(Object topic,
Collection<?> msgs)
Sends given messages with specified topic to the nodes in this projection.
|
void |
send(Object topic,
Object msg)
Sends given message with specified topic to the nodes in this projection.
|
void |
sendOrdered(Object topic,
Object msg,
long timeout)
Sends given message with specified topic to the nodes in this projection.
|
void |
stopLocalListen(Object topic,
IgniteBiPredicate<UUID,?> p)
Unregisters local listener for given topic on local node only.
|
void |
stopRemoteListen(UUID opId)
Unregisters all listeners identified with provided operation ID on all nodes in this projection.
|
IgniteMessaging |
withAsync()
Gets component with asynchronous mode enabled.
|
future, isAsync
ClusterGroup clusterGroup()
GridMessaging
instance belongs.GridMessaging
instance belongs.void send(@Nullable Object topic, Object msg) throws IgniteException
topic
- Topic to send to, null
for default topic.msg
- Message to send.IgniteException
- If failed to send a message to any of the nodes.ClusterGroupEmptyException
- Thrown in case when cluster group is empty.void send(@Nullable Object topic, Collection<?> msgs) throws IgniteException
topic
- Topic to send to, null
for default topic.msgs
- Messages to send. Order of the sending is undefined. If the method produces
the exception none or some messages could have been sent already.IgniteException
- If failed to send a message to any of the nodes.ClusterGroupEmptyException
- Thrown in case when cluster group is empty.void sendOrdered(@Nullable Object topic, Object msg, long timeout) throws IgniteException
The timeout
parameter specifies how long an out-of-order message will stay in a queue,
waiting for messages that are ordered ahead of it to arrive. If timeout expires, then all ordered
messages that have not arrived before this message will be skipped. When (and if) expired messages
actually do arrive, they will be ignored.
topic
- Topic to send to, null
for default topic.msg
- Message to send.timeout
- Message timeout in milliseconds, 0
for default
which is IgniteConfiguration.getNetworkTimeout()
.IgniteException
- If failed to send a message to any of the nodes.ClusterGroupEmptyException
- Thrown in case when cluster group is empty.void localListen(@Nullable Object topic, IgniteBiPredicate<UUID,?> p)
topic
- Topic to subscribe to.p
- Predicate that is called on each received message. If predicate returns false
,
then it will be unsubscribed from any further notifications.void stopLocalListen(@Nullable Object topic, IgniteBiPredicate<UUID,?> p)
topic
- Topic to unsubscribe from.p
- Listener predicate.@IgniteAsyncSupported UUID remoteListen(@Nullable Object topic, IgniteBiPredicate<UUID,?> p) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
topic
- Topic to subscribe to, null
means default topic.p
- Predicate that is called on each node for each received message. If predicate returns false
,
then it will be unsubscribed from any further notifications.Operation ID
that can be passed to stopRemoteListen(UUID)
method to stop listening.IgniteException
- If failed to add listener.@IgniteAsyncSupported void stopRemoteListen(UUID opId) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
opId
- Listen ID that was returned from remoteListen(Object, IgniteBiPredicate)
method.IgniteException
- If failed to unregister listeners.IgniteMessaging withAsync()
withAsync
in interface IgniteAsyncSupport
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC1 Release Date : February 16 2015