pulsar::st) — API preview examplesThese examples exercise the new typed scalable-topics C++ API under include/pulsar/st/. They illustrate the proposed surface and exist to gather community feedback.
Status: API definition only. The implementation (
lib/st/) does not exist yet, so these examples compile but do not yet link. They are wired into the CMake build as a compile-onlyOBJECTlibrary (StExamplesinexamples/CMakeLists.txt) — header-verified on every build, but not linked. Oncelib/stlands they become normaladd_executabletargets.
The pulsar::st API requires C++20 (the rest of the client stays C++17). Syntax-check an example against the headers (no linking):
clang++ -std=c++20 -I ../../include -Wall -fsyntax-only SampleStProducer.cc
| File | Shows |
|---|---|
SampleStProducer.cc | blocking + asynchronous publishing, transactions |
SampleStStreamConsumer.cc | ordered (per-key) delivery, cumulative ack |
SampleStQueueConsumer.cc | parallel delivery, individual ack + nack, dead-letter |
SampleStCheckpointConsumer.cc | externally held position via Checkpoint |
SampleStJsonSchema.cc | a struct as JSON with zero boilerplate (jsonSchema<T>(), reflect-cpp) |
PulsarClient: newProducer / newStreamConsumer / newQueueConsumer / newCheckpointConsumer, each taking a Schema<T>.Expected<T> (a stand-in for std::expected, which is C++23): check it, or call .value() to throw ClientException. Expected<T> is [[nodiscard]], so a failure cannot be silently dropped.Future<T>: addListener(...) to react on completion without blocking, get() to block, or co_await it.jsonSchema<T>() / avroSchema<T>() (reflect-cpp derives the SerDe and the declared schema from the struct — no boilerplate), protobufNativeSchema<T>(), or a custom Schema<T>(serde). reflect-cpp is a required dependency of pulsar::st.