Hazelcast .NET Client

Request a demo
Chat
Contact

Elastically scale .NET caching for your real-world requirements. Hazelcast IMDG is an excellent solution when scaling and speed is of importance.

  • Use the Hazelcast Near Cache feature to store frequently read data in your .NET process. This provides faster read speeds than traditional caches such as Redis or Memcached. Eventual Consistency is also supported.
  • Access all of the Hazelcast data structures plus distributed queues, topics, and more with the Hazelcast IMDG .NET Client.
  • Provides SSL support and Mutual Authentication for your enterprise-level security needs.
  • Support JSON or serialized objects.
Quick Start + Download

Quick Start + Download

Quick Start:

From NuGet package manager console: Install-Package Hazelcast.Net

Version Downloads Documentation
Hazelcast IMDG .NET/CSharp Client 4.1.0 (latest)
09/16/2021
Hazelcast IMDG .NET/CSharp Client 4.0.2
04/06/2021
Hazelcast IMDG .NET/CSharp Client 4.0.1
11/03/2021
Hazelcast IMDG .NET/CSharp Client 4.0.0
08/02/2021

For all downloads please see the Download Archives

Previous Releases
Code Samples

Code Samples

Map Queue Topic List Replicated Map Set MultiMap RingBuffer
Enable Code Wrap
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class MapExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // get distributed map from cluster
            await using var map = await client.GetMapAsync("my-distributed-map");

            // set/get
            await map.SetAsync("key", "value");
            await map.GetAsync("key");

            // concurrent methods, optimistic updating
            await map.PutIfAbsentAsync("somekey", "somevalue");
            await map.ReplaceAsync("key", "value", "newvalue");

            // destroy the map
            await client.DestroyAsync(map);
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class QueueExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // Get a Blocking Queue called "my-distributed-queue"
            var queue = await client.GetQueueAsync("my-distributed-queue");
            // Offer a String into the Distributed Queue
            await queue.PutAsync("item");
            // Poll the Distributed Queue and return the String
            await queue.PollAsync();
            //Timed blocking Operations
            await queue.OfferAsync("anotheritem", TimeSpan.FromMilliseconds(500));
            await queue.PollAsync(TimeSpan.FromSeconds(5));
            //Indefinitely blocking Operations
            await queue.PutAsync("yetanotheritem");
            Console.WriteLine(await queue.TakeAsync());
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;
using Hazelcast.DistributedObjects;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class TopicExample : ExampleBase
    {
        private static void OnMessage(IHTopic sender, TopicMessageEventArgs args)
        {
            Console.WriteLine($"Got message " + args.Payload);
        }

        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // get distributed topic from cluster
            await using var topic = await client.GetTopicAsync("my-distributed-topic");

            // subscribe to event
            await topic.SubscribeAsync(on => on.Message(OnMessage));

            // publish a message to the Topic
            await topic.PublishAsync("Hello to distributed world");

            // allow event to trigger
            await Task.Delay(1_000);

            // destroy the topic
            await client.DestroyAsync(topic);
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class ListExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // Get the Distributed List from Cluster.
            await using var list = await client.GetListAsync("my-distributed-list");

            // Add elements to the list
            await list.AddAsync("item1");
            await list.AddAsync("item2");

            // Remove the first element
            Console.WriteLine("Removed: " + await list.RemoveAsync(0));
            // There is only one element left
            Console.WriteLine("Current size is " + await list.GetSizeAsync());
            // Clear the list
            await list.ClearAsync();

            await client.DestroyAsync(list);
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class ReplicatedMapExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // Get a Replicated Map called "my-replicated-map"
            await using var map = await client.GetReplicatedMapAsync("my-replicated-map");
            // Put and Get a value from the Replicated Map
            var replacedValue = await map.PutAsync("key", "value"); // key/value replicated to all members
            Console.WriteLine("replacedValue = " + replacedValue); // Will be null as its first update
            var value = await map.GetAsync("key"); // the value is retrieved from a random member in the cluster
            Console.WriteLine("value for key = " + value);
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class SetExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // Get the Distributed Set from Cluster.
            await using var set = await client.GetSetAsync("my-distributed-set");

            // Add items to the set with duplicates
            await set.AddAsync("item1");
            await set.AddAsync("item1");
            await set.AddAsync("item2");
            await set.AddAsync("item2");
            await set.AddAsync("item2");
            await set.AddAsync("item3");

            // Get the items. Note that there are no duplicates.
            await foreach (var item in set)
            {
                Console.WriteLine(item);
            }

            await client.DestroyAsync(set);
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class MultiMapExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            // Get the Distributed MultiMap from Cluster.
            await using var multiMap = await client.GetMultiMapAsync("my-distributed-multimap");
            // Put values in the map against the same key
            await multiMap.PutAsync("my-key", "value1");
            await multiMap.PutAsync("my-key", "value2");
            await multiMap.PutAsync("my-key", "value3");
            // Print out all the values for associated with key called "my-key"
            var values = await multiMap.GetAsync("my-key");
            foreach (var item in values)
            {
                Console.WriteLine(item);
            }

            // remove specific key/value pair
            await multiMap.RemoveAsync("my-key", "value2");
        }
    }
}
Get this code sample on Github
using System;
using System.Threading.Tasks;

namespace Hazelcast.Examples.WebSite
{
    // ReSharper disable once UnusedMember.Global
    public class RingBufferExample : ExampleBase
    {
        public async Task Run(string[] args)
        {
            // create an Hazelcast client and connect to a server running on localhost
            await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));

            await using var rb = await client.GetRingBufferAsync("rb");

            // add two items into ring buffer
            await rb.AddAsync(100);
            await rb.AddAsync(200);

            // we start from the oldest item.
            // if you want to start from the next item, call rb.tailSequence()+1
            var sequence = await rb.GetHeadSequenceAsync();
            Console.WriteLine(await rb.ReadOneAsync(sequence));
            sequence += 1;
            Console.WriteLine(await rb.ReadOneAsync(sequence));

            await client.DestroyAsync(rb);
        }
    }
}
Get this code sample on Github
Roadmap

Roadmap

Upcoming .NET Client Features

  • SQL Support: Ability to query data stored in Hazelcast Map declaratively via SQL.
  • ASP.NET Sessions: An implementation of SessionStateProvider so that ASP.Net Sessions can be restored in Hazelcast.
  • IDistributedCache Implementation: Convenience for .NET developers who uses IDistributedCache, a .NET standard for distributed in-memory caching.
  • Entity Framework Integration: Second Level Caching and Query capabilities via lambda queries and LINQ.
  • Backup Acknowledgment: Significantly improving the client performance by eliminating the sync backup wait from the client and send the backup ACK to the client.
  • Configurable Backoff Strategy for Client Reconnections: A highly configurable exponential backoff mechanism for the client with which you can set the duration for waiting after connection failures, an upper limit for the wait, etc.
  • Pipelining API: Adding pipeline to any asynchronous call so that the performance improves.

Recently Released .NET Client Features

  • AtomicLong: Atomically incremented sequence numbers.
  • Hazelcast IMDG 4.0 Changes: Client protocol enhancements, architectural improvements, Serialization improvements.
  • Idiomatic API: Redesign of the API in a way that C# developers used to.
  • Ownerless Client: Simpler design to track member leaves and joins to the cluster.
  • .NET Target Framework Upgrade: The supported .NET Framework version will be v4.5.
  • Auto pass-on NTLM Security Credentials: Allow easy security integration with Windows operating systems.
Client Features

Features Implemented for this Client

DATA STRUCTURES

.NET Client

Map

Queue

Set

List

MultiMap

Replicated Map

Ring Buffer

Topic

Reliable Topic

JCache

N/A

Cardinality Estimator

CONCURRENCY PRIMITIVES

.NET Client

Lock

Condition

Semaphore

AtomicLong

AtomicReference

CountDownLatch

CRDT PN Counter

Flake ID Generator

DISTRIBUTED PROCESSING

.NET Client

Distributed Executor Service

Event Listeners

Sub-Listener Interfaces for Map Listener

Entry Processor

TRANSACTIONS

.NET Client

TxnMap

TxnMultiMap

TxnQueue

TxnList

TxnSet

QUERY

.NET Client

Query (SQL)

Query (Predicates)

Paging Predicates

Partition Predicates

Built-in Predicates

Continuous Query Caching

N/A

Listener with Predicate

Projections

Fast Aggregations

NEAR CACHE

.NET Client

Near Cache Support

HD Memory

Preload Cache from Last Used

Eventual Consistency Control

CONFIGURATION

.NET Client

Declarative Configuration (XML/JSON/YAML)

X (XML)

Programmatic Configuration

Client Configuration Import

Fail Fast on Invalid Configuration

SECURITY

.NET Client

SSL Support

XA Transactions

Mutual Authentication

Authorization

Custom Authentication Modules

MANAGEMENT CENTER

.NET Client

Management Center Integration / Awareness

Client Near Cache Stats

Client Runtime Stats

Client Operating System Stats

CLOUD

.NET Client

Hazelcast Cloud

Kubernetes

AWS

Azure

Google Cloud Platform

Pivotal Cloud Foundry

Docker

Apache jclouds

Consul

etcd

Eureka

Heroku

Zookeeper

INFRASTRUCTURE

.NET Client

Open Client Protocol

Smart Client

Unisocket Client

Lifecycle Service

HeartBeat

Backup Acknowledgement to Client

Diagnostics

SERIALIZATION

.NET Client

DataSerializable

N/A

IdentifiedDataSerializable

Portable Serialization

Custom Serializers

Global Serialization

CLIENT CONNECTIVITY

.NET Client

Connection Strategy

Connection Retry

Blue/Green Deployments and Disaster Recovery

Support for Clients & Languages

Jump into the discussion on our groups.