A Rust client for Apache Pulsar scalable topics, built from the Scalable Topics client specification on the compio runtime.
Status: the first release, 0.1.0, is being prepared.
Producers publish to scalable topics, keeping per-key order across segment splits and
merges, and to regular persistent:// topics through the migration bridge. Queue consumers read every segment of a
topic, following its splits and merges, and acknowledge each message. Stream consumers read the segments the topic's
controller assigns them, each key in order, share segments by entry bucket when they outnumber them, and acknowledge
cumulatively. Checkpoint consumers read every segment, parents before their children, or as members of a group the
segments the controller assigns them, and resume from checkpoints the application keeps, in the Java client's bytes.
All work in the thread-safe, local and blocking APIs, with token and mTLS authentication, directly or through a proxy.
Producers batch messages by entry bucket and compress them, as Java's do. Messages carry the Java client's schemas:
bytes, string, the primitive types, key/value, JSON, Avro and Protobuf, and generic records. The design is in
DESIGN.md, the milestones in PLAN.md.
let client = PulsarClient::builder().service_url("pulsar://localhost:6650").build().await?;
let producer = client.new_producer(Schema::string()).topic("topic://public/default/orders").create().await?;
let id = producer.new_message().key("user-42").value("hello".to_string()).send().await?;
producer.close().await?;
let consumer = client.new_queue_consumer(Schema::string())
.topic("topic://public/default/orders")
.subscription_name("workers")
.subscribe().await?;
let message = consumer.receive().await?;
consumer.acknowledge(message.id()).await?;
client.close().await?;Each release states the version of the Scalable Topics client specification it conforms to, and which of the specification's optional capabilities it implements, in its release notes. The client conforms to version 1.0. It implements the required core, C1 to C15 (conformance §2), and these of the optional capabilities (§3):
| Capability | Implemented |
|---|---|
| Entry-bucketing, producer side | Yes: each batch holds one entry bucket's messages, and each entry is stamped with its bucket hashes. |
| Migration bridge | Yes: persistent:// topics, partitioned or not, and short topic names. |
| Chunking, compression, custom batching | Compression: LZ4, ZLIB, ZSTD and Snappy. No chunking, and no custom batching. |
| Transactions | No. |
| Namespace subscription | No. |
| Dead-letter | No. |
| End-to-end encryption | No. |
| Path | What it is |
|---|---|
crates/apache-pulsar |
The client: producers, Queue, Stream and Checkpoint consumers, layout watches, connections, the pool, lookup, authentication, TLS, the memory limit, and the thread-safe, local and blocking APIs. |
crates/apache-pulsar/examples |
Runnable examples: a producer, the Queue, Stream and Checkpoint consumers, the local and blocking APIs, schemas, TLS and token authentication, and pipelined sends. |
crates/apache-pulsar-protocol |
The sans-IO protocol core: generated protobuf code, framing, the connection, producer and consumer state machines, entry decoding, layouts and routing, message ids. Internal; not a stable API. |
crates/apache-pulsar-testkit |
The simulated broker and cluster, and the deterministic tests of the protocol state machines. Not published. |
checks/ |
Milestone 0 checks: compio behavior, and the handshake against a real broker. |
tools/java-vectors |
Generates test vectors from the Java client. |
xtask |
Repository tasks: protobuf code generation. |
crates/apache-pulsar/examples has one example for each part of the API. They run against a broker on this machine,
or the one PULSAR_URL names. Start a standalone broker that advertises localhost, and once it is up, which takes
a few seconds, run one:
docker run -d --rm --name pulsar -p 6650:6650 -p 8080:8080 apachepulsar/pulsar:5.0.1 bash -c "echo advertisedAddress=localhost >> conf/standalone.conf && exec bin/pulsar standalone"cargo run --example producer| Example | What it shows |
|---|---|
producer |
Keyed messages with properties, a flush and a close, on the default API from a Tokio runtime. |
queue_consumer |
A Shared subscription on every segment: each message acknowledged, one negatively and delivered again. |
stream_consumer |
Segments the controller assigns, each key in order, and cumulative acknowledgments. |
checkpoint_consumer |
No subscription: a checkpoint kept in a file, and a second run that reads on from it. |
local |
The local API: a client per thread, each on its own compio event loop. |
blocking |
The blocking API, without an async runtime. |
schemas |
JSON, Avro and key/value schemas for a struct, and generic records. |
authentication |
TLS with a trusted CA, and a token, a token file or a client certificate. |
pipelining |
Many sends in flight, in order, with buffered, FuturesOrdered and join_all. |
Building needs Rust 1.95 or later, and a C compiler for the ZSTD codec.
cargo test --workspaceThe generated protobuf code is committed, so building needs no protoc. After changing the vendored
crates/apache-pulsar-protocol/proto/PulsarApi.proto, regenerate it (needs protoc 33.1, the version CI checks
with):
cargo run -p xtask -- codegenThe handshake against a real broker:
docker run -d --rm --name pulsar -p 6650:6650 -p 8080:8080 apachepulsar/pulsar:5.0.1 bin/pulsar standalonecargo run -p first-contact -- 127.0.0.1:6650The integration tests start a broker and a proxy in Docker, with TLS, token and mTLS authentication, and remove
them when they finish. A Java tool they run in the broker container is compiled in an eclipse-temurin JDK
container. cargo test skips them; they need Docker running:
cargo test -p apache-pulsar --test integration