tree: dbd4d69ab4db97aab22e3e1675214a3aec2c880c [path history] [tgz]
  1. Abstractions/
  2. Exceptions/
  3. Extensions/
  4. Internal/
  5. Schemas/
  6. AuthenticationFactory.cs
  7. CompressionType.cs
  8. ConsumerOptions.cs
  9. ConsumerState.cs
  10. ConsumerStateChanged.cs
  11. DotPulsar.csproj
  12. EncryptionPolicy.cs
  13. ExceptionContext.cs
  14. FaultAction.cs
  15. MessageId.cs
  16. MessageMetadata.cs
  17. PackageIcon.png
  18. ProcessingOptions.cs
  19. ProducerAccessMode.cs
  20. ProducerOptions.cs
  21. ProducerState.cs
  22. ProducerStateChanged.cs
  23. PulsarClient.cs
  24. ReaderOptions.cs
  25. ReaderState.cs
  26. ReaderStateChanged.cs
  27. README.md
  28. RoundRobinPartitionRouter.cs
  29. Schema.cs
  30. SchemaInfo.cs
  31. SchemaType.cs
  32. SinglePartitionRouter.cs
  33. SubscriptionInitialPosition.cs
  34. SubscriptionType.cs
src/DotPulsar/README.md

DotPulsar

Let‘s take a look at a “Hello world” example, where we first set up a consumer and then produce a message. Note that the topic and subscription will be created if they don’t exist.

Creating the client

Before creating readers, consumers, and producers, we need to create a client.

using DotPulsar;
using DotPulsar.Extensions;

await using var client = PulsarClient.Builder().Build();  // Connecting to pulsar://localhost:6650

Consuming

await using var consumer = client.NewConsumer(Schema.String)
    .SubscriptionName("MySubscription")
    .Topic("persistent://public/default/mytopic")
    .InitialPosition(SubscriptionInitialPosition.Earliest)
    .Create();

await foreach (var message in consumer.Messages())
{
    Console.WriteLine($"Received: {message.Value()}");
    await consumer.Acknowledge(message);
}

Producing

await using var producer = client.NewProducer(Schema.String).Topic("persistent://public/default/mytopic").Create();
var messageId = await producer.Send("Hello World");