DotPulsar The official .NET client library for Apache Pulsar. DotPulsar is written entirely in C# and implements Apache Pulsar's binary protocol. What's new? Have a look at the changelog. Getting Started 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…
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.
Supported features
Service discovery
Automatic reconnect
TLS connections
Pulsar Proxy
Producer - send with custom metadata
Producer - send with event time, sequence id, and delayed message delivery
Producer - send with key and ordering key
Producer - partitioned topics
Consumer - subscription with initial position and priority level
Consumer - subscription types exclusive, shared, failover, and key shared
Consumer - multi-topic subscriptions
Consumer - receive and single + cumulative acknowledge
Consumer/Reader - seek on message-id and publish time
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.
评论