Previous: 8. Quality.
Status: proposed. What is decided is the direction: a classic (v4) API for regular topics, in a crate of its own, so that other languages can wrap this client's core. The rest of this document is a proposal until it is settled; §12 lists what is open.
apache-pulsar is a scalable-topics client. It reaches a persistent:// topic only through the migration bridge (6 §8), which needs a 5.0 broker, and there it offers the V5 API: Stream, Queue and Checkpoint consumers, not the classic subscription types.
The clients that other languages use today offer the classic API, and every topic created before 5.0 is a regular topic. A core that those languages wrap has to offer that API too, and work with the brokers their users run. The classic crate does both, over the same connections and the same single-topic engine as apache-pulsar, so that the two don't drift apart.
The classic crate is Java‘s v4 client API (org.apache.pulsar.client.api), which the other languages’ clients follow, written the way apache-pulsar writes Java V5's (7). Proposed for the first version:
| Area | First version | Notes |
|---|---|---|
| Producer, on a topic partitioned or not | Yes | Routing modes and hashing schemes, batching, compression, access modes, dedup, delivery time (§6.1). |
Consumer: Exclusive, Shared, Failover, Key_Shared | Yes | Acks, negative acks, ack timeout, seek, unsubscribe; partitioned topics (§6.2). |
| Consumer on several topics, by list or by pattern | Yes | §6.3. |
| Reader | Yes | §6.4. |
| Schemas, authentication, TLS | Yes | apache-pulsar's, shared (§3). |
non-persistent:// topics | Later | Unless the first languages need them (§12, question 4). |
| Dead-letter and retry topics, chunking, end-to-end encryption, transactions | Later | Built once in the shared engine, for both crates (Plan). |
| Table views, broker-confirmed acks | Later | |
| HTTP lookup, an admin client | No | As for apache-pulsar (1 §5). |
What the first version has to cover depends on which languages wrap it first (§12, question 4).
A classic API could have been a module of apache-pulsar. A crate of its own needs the engine somewhere both crates can reach. Proposed: a crate of its own for the engine.
| Crate | Contents | Stability |
|---|---|---|
apache-pulsar-protocol | As today, plus the classic state machines (§7). | Internal: 0.x, pinned by an exact version. |
apache-pulsar-core (new) | Moved out of apache-pulsar: the driver, the connections, the loops and the single-topic engine, and what both APIs share: the client, authentication, schemas and errors. | Internal, like the protocol crate. |
apache-pulsar | The scalable layer and the V5 API. | Semver, as today. |
apache-pulsar-classic (new) | The classic API. | Semver. |
A type both APIs expose, a schema or an error, is defined once in core and re-exported by both crates, so changing it changes both crates' APIs. The classic crate carries none of the scalable layer, and a binding links both API crates over one core.
The alternative is for the classic crate to depend on apache-pulsar, which would expose its engine in a hidden module. It is a smaller change, but it puts an unstable surface inside the crate that makes semver promises, and classic users would compile the scalable layer.
An application or a binding that uses both kinds of topics should run one set of loops and one connection pool: two clients would double the threads, and the connections to each broker. So the loops, the pools and the client‘s configuration live in core, and each API crate’s client is a handle on a core client. How an application gets both handles on one core client is settled with the API (§12, question 6).
The same shape as apache-pulsar (7):
PulsarClient, with new_producer, new_consumer and new_reader, each taking a schema.apache-pulsar does for V5.apache-pulsar's Error and ErrorKind, plus the kinds the classic API needs.MessageId: Java‘s v4 message id: ledger, entry, partition and batch index. Its bytes are Java’s MessageId.toByteArray(), so that a position stored by one SDK can be restored by another. The protocol crate's EntryId is that id already; the V5 id embeds it (7 §7).Java's v4 client is the reference wherever this document says nothing else, as Java V5 is for apache-pulsar.
Partitioned topics. CommandPartitionedTopicMetadata gives the partition count. The producer runs one single-topic producer per partition, all on its loop, as a scalable producer runs one per segment. It checks the count again every minute (Java's autoUpdatePartitionsInterval) and adds producers for new partitions.
Routing as in Java: round robin by default, where a keyed message goes to its key‘s partition and the others rotate; a single partition; or the application’s router.
Hashing schemes. Each client picks a keyed message's partition with a default hash of its own, and no two agree:
JavaStringHash, String.hashCode() without its sign bit.BoostHash, Boost‘s string hash. Python, which wraps the C++ client, has no setting for it; Node, which wraps it too, uses it unless told otherwise. The C++ client’s JavaStringHash hashes the UTF-8 bytes, so it matches Java's on ASCII keys only.JavaStringHash too, over the UTF-8 bytes and without clearing the sign bit. It differs from Java‘s on keys that aren’t ASCII, and on about half of random keys when the partition count isn't a power of two.apache-pulsar: Murmur3_32Hash, as the spec has it (6 §8).Murmur3_32Hash is the one scheme that Java, C++ and Go compute alike for every key. The classic producer offers it and JavaStringHash, Java‘s two. Its default, and whether a binding that replaces the C++ or Go client reproduces that client’s scheme, are open (§12, question 7).
Batching with Java v4‘s defaults, which are V5’s: on, 1 ms, 1000 messages, 128 KiB. A partition has one open batch: the engine's one-bucket case (5 §2).
Compression as in apache-pulsar, with the v4 setting V5 doesn't expose: Java v4 leaves a payload of 4 KiB or less uncompressed (compressMinMsgBodySize).
Access modes, sequence ids, send timeout, delivery time: the engine‘s, per partition, as Java’s v4 ProducerImpl has them.
What a v4 client would see differently. The engine writes every entry in the batch format, so a lone message is a batch of one, with batch index 0 in its id. Java writes a lone message as a plain entry, with batch index -1, whether batching is on or off (§12, question 8). The migration bridge marks its producers and consumers with __pulsar.v5.managed=true (6 §8); classic ones don't carry it.
Key_Shared.CommandActiveConsumerChange. The consumer passes it to an optional listener, as Java's ConsumerEventListener does.Key_Shared: auto-split hash ranges, Java's default, or sticky ranges the application gives. The engine subscribes Key_Shared only with entry-bucket dispatch today (5 §3).CommandSeek). The consumer drops what it holds, as Java's does.A consumer on a list of topics, or on the topics of one namespace that match a pattern. As in Java, the pattern‘s topics come from CommandGetTopicsOfNamespace, then from the topic-list watch (CommandWatchTopicList) where the broker advertises supports_topic_watchers, which the connection reads already. A check every minute by default reconciles the list, through the watch when it is connected and with CommandGetTopicsOfNamespace otherwise. The V5 API’s namespace subscription, a later capability, needs the same commands.
The engine‘s reader (5 §4), on a topic partitioned or not, plus what the classic reader adds: an inclusive start, seek, and has_message_available, which asks for the topic’s last message id with CommandGetLastMessageId, as the Checkpoint consumer does already.
2 §1 has the segment engine as the classic client for one topic, under the scalable layer. The consumer‘s code is cut that way: SegmentConsumer, in the protocol crate, is one topic’s consumer. The producer‘s isn’t yet:
Producer is the whole scalable producer. Its per-segment state is one struct, but that struct also holds the scalable layer’s: whether the segment retires, its parked messages, its bucket boundaries. The code that registers, batches and completes sends is in the scalable Producer.So the first step carves out a single-topic producer, which the scalable producer and the classic producer both drive, and splits each task‘s work on one topic from its following of layouts. It changes no behavior: the existing tests pass unchanged. How big it is shows only once it starts, which makes it the plan’s main risk.
The protocol crate also needs what the scalable layer never used:
CommandPartitionedTopicMetadata, whose generated types are there, unused.CommandGetTopicsOfNamespace and the topic-list watch.CommandActiveConsumerChange.CommandSeek.Key_Shared without entry-bucket dispatch.apache-pulsar needs 5.0 (1 §3). The classic crate sends no scalable-topic command, so nothing ties it to 5.0, and its users' brokers are older too. The connection layer records a broker's feature flags and refuses none; only scalable-topic commands need supports_scalable_topics (4 §3). But nothing has run below 5.0.1 yet, and an older broker lacks some features, which the client then does without, as Java does: the topic-list watch, for one.
Proposed: support every Pulsar release line still maintained, and run the integration tests against each one (§12, question 2).
tests/PORTING.md maps the V5 tests (8 §2.1) is a step of its own.apache-pulsar-core and apache-pulsar-classic join the release (RELEASE.md): its cargo publish commands and their order, the CI dry run, the minimum-Rust-version job, and an exact pin on core, as on the protocol crate. One source release holds every crate, and RAT checks the license header of every new file.
Not designed here. The classic crate keeps what 1 §6 asks of a core that others wrap: the thread-safe API owns its threads, its futures run on any executor, and configuration is plain data. Whether the bindings share one C ABI or use native bindings such as PyO3 and napi-rs is decided with them.
apache-pulsar-core (§3, proposed), or the classic crate on apache-pulsar?apache-pulsar's public API.apache-pulsar-classic and apache-pulsar-core. The docs already say “classic”; “v4” would tie the name to a version, and “legacy” sounds deprecated.JavaStringHash, which matches Java v4 producers, or Murmur3_32Hash, which matches the migration bridge and which every client that offers it computes alike? And does a binding that replaces the C++ or Go client reproduce that client‘s scheme, BoostHash or Go’s JavaStringHash, so that its users' keys keep their partitions (§6.1)?