From RabbitMQ to Apache Pulsar in .NET with DotPulsar

RabbitMQ is a great default. Here's when Apache Pulsar starts to make sense for a .NET messaging system, and how to move without a risky cutover.

RabbitMQ is an excellent message broker, and for most systems it's the right default. We've used both RabbitMQ and Apache Pulsar in high-throughput .NET systems. These are the situations where Pulsar earns its extra complexity.

When Pulsar is worth it

  • You need to replay messages. Pulsar stores messages durably and lets a subscription rewind. With classic RabbitMQ queues, a consumed message is gone.
  • You serve many tenants. Pulsar's tenant/namespace/topic hierarchy gives each customer its own space, with policies such as retention and rate limits per namespace.
  • Ordering per key matters at scale. The Key_Shared subscription type spreads work across consumers while keeping messages with the same key in order.
  • Volume keeps growing. Pulsar separates serving from storage, so you can scale brokers and storage independently.

If none of these apply, stay on RabbitMQ.

The basics with DotPulsar

DotPulsar is the official .NET client for Apache Pulsar.

await using var client = PulsarClient.Builder()
    .ServiceUrl(new Uri("pulsar://localhost:6650"))
    .Build();

await using var producer = client.NewProducer(Schema.String)
    .Topic("persistent://tenant-a/messaging/outbound")
    .Create();

await producer.Send("hello");

await using var consumer = client.NewConsumer(Schema.String)
    .SubscriptionName("delivery-workers")
    .SubscriptionType(SubscriptionType.Shared)
    .Topic("persistent://tenant-a/messaging/outbound")
    .Create();

await foreach (var message in consumer.Messages(cancellationToken))
{
    await HandleAsync(message.Value());
    await consumer.Acknowledge(message, cancellationToken);
}

Acknowledge only after the work is done. If the consumer crashes before acknowledging, Pulsar redelivers the message.

Migrating without a big-bang cutover

  1. Put an interface in front of messaging. If your code calls RabbitMQ directly everywhere, first wrap publishing and consuming behind your own abstraction.
  2. Move one flow at a time. Pick a low-risk queue, publish to both brokers, and run the new Pulsar consumer in shadow mode, comparing results without acting on them.
  3. Switch consumers, then producers. Once the Pulsar side matches, make it the real consumer, then stop publishing to RabbitMQ for that flow.
  4. Watch the queues. Backlog size, consumer count and the age of the oldest unacknowledged message tell you within minutes whether the new flow is keeping up.

Moving flow by flow means a problem affects one flow you can roll back, not the whole platform.

Dealing with this in your own system? We do this work for a living. The first call is free.

Book a call