| commit | e0da267ce7a5a37f71023ab8464ab64d2d4cecf3 | [log] [tgz] |
|---|---|---|
| author | Zhangjian He <hezhangjian97@gmail.com> | Mon Sep 08 11:31:11 2025 +0800 |
| committer | Zhangjian He <hezhangjian97@gmail.com> | Mon Sep 08 11:31:11 2025 +0800 |
| tree | 8a27352488c2bcbd31c656876997e2c50f9ad610 | |
| parent | 17653cf95557c261fecbdbc5188d35483922c0ef [diff] |
fix: Replace Dictionary with ConcurrentDictionary in Consumer to fix KeyNotFoundException - Replace Dictionary<string, SubConsumer<TMessage>> with ConcurrentDictionary to ensure thread safety - Fix KeyNotFoundException that occurs in multi-threaded scenarios when accessing _subConsumers - Add System.Collections.Concurrent using directive - Minimal change with maximum impact for thread safety Fixes: KeyNotFoundException in Consumer.Acknowledge method when multiple threads access the dictionary concurrently
The official .NET client library for Apache Pulsar.
DotPulsar is written entirely in C# and implements Apache Pulsar's binary protocol.
Have a look at the changelog.
Let‘s take a look at a “Hello world” example, where we first produce a message and then consume it. Note that the topic and subscription will be created if they don’t exist.
First, we need a Pulsar setup. See Pulsar docs for how to set up a local standalone Pulsar instance.
Install the NuGet package DotPulsar and run the follow code example:
using DotPulsar; using DotPulsar.Extensions; const string myTopic = "persistent://public/default/mytopic"; // connecting to pulsar://localhost:6650 await using var client = PulsarClient.Builder().Build(); // produce a message await using var producer = client.NewProducer(Schema.String).Topic(myTopic).Create(); await producer.Send("Hello World"); // consume messages await using var consumer = client.NewConsumer(Schema.String) .SubscriptionName("MySubscription") .Topic(myTopic) .InitialPosition(SubscriptionInitialPosition.Earliest) .Create(); await foreach (var message in consumer.Messages()) { Console.WriteLine($"Received: {message.Value()}"); await consumer.Acknowledge(message); }
For a more in-depth tour of the API, please visit the Wiki.
For a horizontal comparison with more language-specific clients, see Client Feature Matrix.
Help prioritizing the roadmap is most welcome, so please reach out and tell us what you want and need.
Apache Pulsar has a Slack instance, and there you'll find us in the #dev-dotpulsar channel.
We use SemVer for versioning. For the versions available, see the tags on this repository.
Contributions are welcomed and greatly appreciated. See also the list of contributors who participated in this project. Read the CONTRIBUTING guide for how to participate.
If your contribution adds Pulsar features for C# clients, you need to update both the Pulsar docs and the Client Feature Matrix. See Contribution Guide for more details.
This project is licensed under Apache License, Version 2.0.