Clients

Hazelcast .NET Client

Elastically scale .NET caching for your real-world requirements. Hazelcast 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 .NET Client.
  • Provides SSL support and Mutual Authentication for your enterprise-level security needs.
  • Support JSON or serialized objects.

Quick Start + Download

Quick Start

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

Downloads

Version Downloads Documentation
Hazelcast IMDG .NET/CSharp Client 5.1.0 (latest)
08/11/2022
Hazelcast IMDG .NET/CSharp Client 5.0.2
07/07/2022
Hazelcast IMDG .NET/CSharp Client 5.0.1
08/11/2022
Hazelcast IMDG .NET/CSharp Client 4.1.0
08/11/2022

For all downloads please see the Download Archives

Previous Releases

Code Samples

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

Upcoming .NET Client Features

  • Compact Serialization: The new language independent serialization type that have many advantages including high performance and usability.
  • LINQ Support: Ability to use Microsoft's Language-Integrated Query for querying data in Hazelcast.
  • 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.

Recently Released .NET Client Features

  • Blue/Green Failover: The support of the blue/green deployment and disaster recovery features.
  • FencedLock: The linearizable and distributed implementation of a lock.
  • Support for .NET 6.0
  • SQL Support: Ability to query data stored in Hazelcast Map declaratively via SQL.
  • Flake ID Generator: Used to generate cluster-wide unique identifiers.
  • 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.

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

ID Generator

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

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)

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

Management Center Integration / Awareness

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

Compact Serialization (Beta)

DataSerializable

N/A

IdentifiedDataSerializable

Portable Serialization

Custom Serialization

Global Serialization

Client Connectivity
.NET Client

Connection Strategy

Connection Retry

Blue/Green Deployments and Disaster Recovery