Skip to content

M7 audit, part 2: examples - #44

Merged
merlimat merged 1 commit into
mainfrom
m7-examples
Nov 23, 2026
Merged

merlimat merged 1 commit into
mainfrom
m7-examples

Conversation

@merlimat

Copy link
Copy Markdown
Contributor

The second part of M7's audit (PLAN.md, M7): examples, which the repository didn't have. The error model is #38;
the rustdoc follows in its own pull request.

What it adds

crates/apache-pulsar/examples, one example for each part of the API. Each runs against a broker on this machine,
or the one PULSAR_URL names, and takes another topic as its first argument.

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.
  • The default API's examples run on Tokio: the client's futures run on any executor. local runs its own compio
    loops, and blocking none.
  • pipelining uses the three patterns that send's rustdoc recommends, and that
    pipelining_combinators_keep_send_order (M2) checks keep send order, and says what loses the order: a send spawned
    as a task of its own, and a send future dropped after its first poll.
  • schemas takes the json and avro features, on by default, as its required-features.
  • authentication takes its setup from the environment. Its token file is read again for each connection, by the
    standard library, as a provider's future runs on the client's event loop, not on Tokio.

Dev-dependencies: tokio, for #[tokio::main], and futures, for the combinators. Both were in the lock already,
through testcontainers, so Cargo.lock only gains the two edges. The README lists the examples, with the command for
a standalone broker that advertises localhost.

CI

The existing steps build every example on Linux and macOS: cargo clippy --workspace --all-targets -- -D warnings
and cargo test --workspace. The build without default features doesn't build examples; with them, schemas is
skipped by its required features. No step is added. Coverage doesn't count the examples, which can't run there:
cargo-llvm-cov leaves examples/ out of its report, and a stub example left the totals where they were.

Testing

Each example ran against apachepulsar/pulsar:5.0.1 standalone: the producer; the Queue consumer, which got the
negatively acknowledged message again with a redelivery count of 1; the Stream consumer; the Checkpoint consumer
twice, the second run reading only the four messages stored after the first; the local example's 20 messages from two
loops; blocking; schemas, with the generic record's fields; pipelining's 12,000 sends. authentication ran against a
broker with TLS and token and TLS authentication, with a token, a token file and a client certificate, and failed with
Authentication without credentials.

The second part of M7's audit: examples, one for each part of the
API, in crates/apache-pulsar/examples. Each runs against a broker on
this machine, or the one PULSAR_URL names.

- 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: the segments the controller assigns, and cumulative
  acknowledgments.
- checkpoint_consumer: a checkpoint kept in a file, and a second run
  that reads on from it.
- local: 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; it takes the json and avro features.
- 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, the patterns send's rustdoc recommends.

Dev-dependencies: tokio and futures, both in the lock already through
testcontainers. CI's clippy --all-targets and cargo test build the
examples; cargo-llvm-cov leaves them out of the coverage report. The
README lists them, with the command for a standalone broker.
@merlimat
merlimat merged commit baa4a13 into main Nov 23, 2026
11 checks passed
@merlimat
merlimat deleted the m7-examples branch November 23, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant