Apache Ignite.NET Documentation

The Apache Ignite .NET Developer Hub

Welcome to the Apache Ignite .NET developer hub. You'll find comprehensive guides and documentation to help you start working with Apache Ignite.NET as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Local and Remote Events

Get notified of any state change or event occurring cluster-wide.

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.

Distributed events functionality is provided via IEvents interface. You can get an instance of IEvents from Ignite as follows:

IIgnite ignite = Ignition.Start()

IEvents evts = ignite.GetEvents();

Subscribe for Events

Listen methods can be used to receive notification for specified events happening in the cluster. These methods register a listener on local node for the specified events. Whenever the event occurs on any node, the listener is notified.

void Events()
{
    using (IIgnite ignite = Ignition.Start())
    {
        IEvents events = ignite.GetEvents();

        var listener = new CacheEventListener();

        // Subscribe to cache events.
        events.LocalListen(listener, EventType.CacheObjectPut, EventType.CacheObjectRead);

        // Generate event by adding cache entry.
        ignite.GetOrCreateCache<int, int>("myCache").Put(1, 1);

        // Unsubscribe.
        events.StopLocalListen(listener);
    }
}

class CacheEventListener : IEventListener<CacheEvent>
{
    public bool Invoke(CacheEvent evt)
    {
        Console.WriteLine("Received event [evt={0}, key={1}, oldVal={2}, newVal={3}]", evt.Name, evt.Key, evt.OldValue, evt.NewValue);

        return true; // Continue listening.
    }
}

📘

EventType class defines various event type constants that can be used with listen methods. IEventListener generic argument should correspond to subscribed event types (CacheEvent for EventType.Cache*, for example). Alternatively, IEvent can be used to accept any kind of events.

🚧

Event types passed in as parameter in LocalListen(...) methods must also be configured in IgniteConfiguration. See configuration example below.

Query for Events

All events generated in the system are kept locally on the local node. IEvents API provides methods to query for these events.

Remote Events

RemoteQuery(...) method queries for events on remote nodes in this projection using the passed in predicate filter.

Configuration

To get notified of any tasks or cache events occurring within the cluster, includeEventTypes property of IgniteConfiguration must be enabled.

var cfg = new IgniteConfiguration
{
    IncludedEventTypes = {EventType.TaskFailed, EventType.JobFinished}
};
<igniteConfiguration>                            
    <includedEventTypes>
        <int>TaskFailed</int>
        <int>JobFinished</int>
    </includedEventTypes>
</igniteConfiguration>
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
        ... 
    <property name="includeEventTypes">
        <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
        <util:constant static-field="org.apache.ignite.events.EventType.EVT_JOB_FINISHED"/>
    </property>
    ...
</bean>

By default, event notifications are turned off for performance reasons.

👍

Since thousands of events per second are generated, it creates an additional load on the system. This can lead to significant performance degradation. Therefore, it is highly recommended to enable only those events that your application logic requires.

Updated about a year ago

Local and Remote Events


Get notified of any state change or event occurring cluster-wide.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.