Expand description
A durable, at-least-once MPSC queue backed by in-memory and durable backends.
Items are written to a Store and survive process and machine crashes.
Delivery is at-least-once: an item is removed only once the consumer acks it,
so a crash between handling and ack redelivers it. The core is synchronous and
runtime-agnostic.
use persistent_queue::{Builder, MemStore};
let (tx, rx) = Builder::new(MemStore::new()).capacity(1024).open().unwrap();
tx.push(b"job").unwrap();
let item = rx.reserve().unwrap().unwrap();
assert_eq!(&*item, b"job");
item.ack().unwrap();For typed messages, Builder::open_typed wraps the queue with a Codec that
encodes on push and decodes on reserve (serde and bincode behind the serde
feature). With the tokio feature, [Builder::open_async] gives async
producer/consumer handles that run store I/O on tokio’s blocking pool and wait
(for capacity, or the next item) asynchronously.
See DESIGN.md for the on-disk layout, crash recovery, and durability model.
Structs§
- Builder
- Builds a queue over a
Store. - Codec
Error - An encode or decode failure, carrying the underlying codec’s message.
- Consumer
- The consumer half. Single consumer, so it does not implement
Clone. - MemStore
- In-memory
Storebacked by aBTreeMap. Not persistent;durableis a no-op. Useful as the default, for tests, and as a benchmark baseline. - Producer
- The producer half. Clone it for multiple producers.
- Reserved
- A reserved (in-flight) item. Derefs to its bytes;
ackremoves it,nackor drop returns it for redelivery. - Typed
Consumer - The consumer half of a typed queue. Single consumer.
- Typed
Producer - The producer half of a typed queue. Clone it for multiple producers.
- Typed
Reserved - A reserved, decoded item. Derefs to the value;
ackremoves it whilenackor drop returns it for redelivery.
Enums§
- Durability
- How writes are made durable.
- Op
- A single write in a
Store::commitbatch. - Open
Error - Error from opening a queue over a store.
- Push
Error - Error from a blocking
Producer::push. - Reserve
Error - Error from
TypedConsumer::reserve. - TryPush
Error - Error from
Producer::try_push. - Typed
Push Error - Error from
TypedProducer::push.
Traits§
- Codec
- Encodes a message type to bytes for the store and decodes it back.
- Store
- An ordered key/value byte store: the durable substrate under the queue.
Type Aliases§
- Ends
- The producer and consumer ends returned by
Builder::open. - KeyValue
- A key/value pair returned by a store seek.
- Typed
Ends - The producer/consumer pair returned by
Builder::open_typed.