/ruststream:ruststream-brokerfrom ruststream
Guides writing, changing, or debugging a RustStream broker crate that adapts ruststream to a broker client. Covers lifecycle, publishers, subscriptions, batching, testing, and conformance suites.
Ships in ruststream. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A broker crate depends on ruststream = { version = "0.7", default-features = false } and
implements the core's traits over one client library. The contract is checked by the
conformance suites, which run in process and against a real server. The hub of the contract is
the Broker trait on docs.rs;
MemoryBroker (crates/memory of the core) is the reference implementation, and
ruststream-nats is a worked crate over
a real client. This guidance targets the 0.7 line; a broker crate's version tracks the core's
minor line.
Depth:
MyBroker::new(addrs) is synchronous and does no I/O.
Broker::connect(self) -> Result<Connected, Error> opens the client;
ConnectedBroker::shutdown(self) -> Result<Closed, Error> tears it down and never blocks or
panics. Keep tokio::runtime::Handle::current() from connect in the connected form and spawn
the broker's own tasks (timers, reply dispatchers) through it.Subscriber::stream(&mut self) yields deliveries that implement
IncomingMessage (payload, headers, redelivery count) and Settle. Settle::ack(self) and
Settle::nack(self, requeue) consume the delivery; a transport without acks answers
AckError::Unsupported. Override redelivery_count(&self) -> Option<u64> where the transport
counts deliveries (the first delivery answers 1). The trait has no error type of its own.
A device broker whose deliveries wait in a channel or a socket returns a ReadyHint from
Subscriber::ready_hint (may_be_ready is true whenever the next poll could yield, the end
after a shutdown included), so the embedded app skips the poll of an idle subscription;
harness::local_readiness holds it to that.Subscribe on the connected form for #[subscriber("name")], and a
descriptor implementing SubscriptionSource<Connected> for the broker's own options. Both
declare type Copies: AddressedCopies (implement RedeliveryAddressed on the descriptor),
NamedCopies, or BrokerMoves.PublishPolicy<Connected>, whose
async pair builds the live Publisher. DefaultPublish on the connected form names the
policy replies and retry copies use. Per-message settings are Publisher::Options, adjusted
by a step trait over PublishBuilder.BatchSubscriber (offer it, assembled with
the core's BufferedSubscriber when the transport delivers one at a time),
TransactionalPublisher, OwnedTransactions, RequestReply, Partitioned,
Seekable / Seeker, Positioned, Carries, DescribeServer.pub use ruststream::prelude::*;, the crate's service-facing types, and the
policies under the uniform names Publish, TransactionalPublish, Request.testing feature: InProcess on the production broker,
TestableBroker on its connected form, register_testable_broker!(MyBroker).pair is async and fallibleWrong: fn pair(self, conn: &Connected) -> MyPublisher.
Correct: async fn pair(self, connected: &Connected) -> Result<MyPublisher, PairError>, with
type Live = MyPublisher;. DefaultPublish is impl DefaultPublish for Connected { type Policy = MyPublish; },
and the policy is Default.
type Copies on Subscribe and on each SubscriptionSource. AddressedCopies pairs with
impl RedeliveryAddressed<Connected> for MyOptions, whose async redelivery_address answers the
name a publish uses to reach the subscription again. BrokerMoves is for a server that moves
the delivery itself (a dead-letter exchange, a redrive policy). declare_retry hands every
descriptor the registration's max_attempts and dead_letter before it subscribes; apply them
where the server has a mechanism for both.
A publisher made before shutdown errors after it; a value of Options the transport cannot
honour is a publish error; the in-process transport rejects what the server rejects and keeps
what the server keeps (Backlog::Delivered for a queue or a log). A silent success is a defect.
A priority, a QoS or an ordering key is a field of Publisher::Options (every field optional)
and a step on PublishBuilder bounded on PublishSink<Options = MyOptions>. It never rides a
header and never wraps the publisher: a wrapper loses the mount site's codec and the harness's
attribution.
use ruststream::conformance::harness;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn routing() {
// In process: the production broker, connected through `connect_in_process`.
harness::run_suite(|| MyBroker::new("my://localhost")).await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn lifecycle() {
let Ok(url) = std::env::var("MY_BROKER_TEST_URL") else { return };
// Closures, not method paths: the bounds are higher-ranked.
harness::lifecycle(
move || MyBroker::new(url.clone()),
|name| MyOptions::new(name),
|connected| connected.publisher(),
)
.await;
}
Send serves the embedded runnerA client that holds Rc or RefCell (a thread-per-core client, an embedded network stack) has
no Send futures to promise. The lifecycle traits (Broker, ConnectedBroker, Subscribe,
SubscriptionSource, PublishPolicy) carry no Send, so it implements them as they are. The
per-message traits (Subscriber, Settle, Publisher and the capability traits) are one trait
per concept for every runtime: their futures ask for Send when tokio or compio is on and for nothing on
the embedded runner alone, so the same impl serves a device and a server. IncomingMessage gives
the accessors of a delivery. Error types stay Send + Sync + 'static. A build with both runtime
features takes the stricter bound, so a type that holds Rc does not compile next to tokio. The
tokio and compio runners ask for Send + Sync where they hand a delivery to a task or a core. The suites of the local family
(run_local_suite, local_lifecycle) come with the facade's conformance feature, which turns
tokio on, so they check such a client in a build where its types are Send.
DescribeServer builds its ServerSpec with ServerSpec::from_url (host_from_url per address),
which drops the userinfo. The generated AsyncAPI document is published.
| Symptom | Fix |
|---|---|
async fn new(..) that connects | sync new, I/O in connect |
tokio::spawn in a publish or settle path | spawn through the Handle kept from connect |
redelivery_address written on SubscriptionSource | impl RedeliveryAddressed with type Copies = AddressedCopies |
a pub use in the prelude that shadows a core name | rename it; an explicit re-export silently beats the glob |
| an emulated capability | implement only what the transport supports |
| a hand-written test double broker | the production broker's InProcess mode |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
5 skills in this plugin
/ruststreamUse when writing, changing or debugging a service built on the RustStream messaging framework (crates `ruststream` and `ruststream-*` broker crates such as nats, rdkafka, lapin, fred): subscriber handlers, the app, replies and publishing, acks, retries and dead letters, state, codecs, batches, workers and threads, routers, middleware, running beside an HTTP server, and the framework's compile errors. Use it whenever the project depends on `ruststream`./ruststream-coreUse when changing the RustStream core repository itself (powersemmi/ruststream: the crates under `crates/`, the `ruststream` facade in `crates/ruststream` with its `tests/` and `examples/`, the site), as a contributor: public items, errors, features, doctests, compile-fail snapshots, conformance suites, the local gates and the pull request./npx claudepluginhub powersemmi/ruststream --plugin ruststreamOther plugins' skills for the same job