walchan
A persistent channel backed by a write-ahead log (WAL).
walchan provides channel and sync_channel APIs intentionally close to
std::sync::mpsc, while persisting messages to disk and providing
at-least-once delivery across process restarts.
This crate is useful when you want a simple, local, crash-resilient message queue with familiar channel semantics.
Key semantics
- Persistence: every
send()appends to a WAL file. - At-least-once delivery: messages delivered but not yet acknowledged may be re-delivered after a crash.
- RAII acknowledgement: receiving yields a
Delivery<T>. Dropping it acknowledges the message. - Commit batching: receiver-side progress commits can be batched for higher throughput.
Feature flags
-
fsync
Enables callingFile::sync_data()for real durability. Without this feature,sync_data()is compiled as a no-op and durable modes degrade to “flush-only” behavior. -
stress
Enables stress tests.
Enable features explicitly:
# or
Usage
1. Unbounded channel
(like std::sync::mpsc::channel)
use ;
2. Bounded channel with timeout send
(like std::sync::mpsc::sync_channel)
use ;
use Duration;
;
3. Receiver commit batching
(throughput vs. re-delivery window)
use ;
use Duration;
API overview
Channel creation
channel(path) -> (Sender<T>, Receiver<T>)sync_channel(path, bound) -> (SyncSender<T>, Receiver<T>)
Sending
Sender::sendSyncSender::{send, try_send, send_timeout}
Receiving
Receiver::{recv, try_recv, recv_timeout, recv_deadline}Receiver::try_iterReceiverimplementsIntoIterator
Receiving yields Delivery<T>
*delivery/delivery.get()to access the payload- Dropping the
Deliveryacknowledges it
Durability
Durability is configured via Options:
-
Durability::SyncPerSend
Flush + fsync on every send (strongest, slowest) -
Durability::FlushOnly
Flush only (fastest) -
Durability::SyncEvery { max_ops, max_delay }
Periodic fsync
Note: without the
fsyncfeature enabled, fsync calls are no-ops.
Caveats
-
Delivery is at-least-once.
Your application must tolerate duplicates (e.g. via idempotency). -
Acknowledgement is RAII-based.
If the process crashes before aDeliveryis dropped and committed, the message may be re-delivered. -
walchanis a simple local WAL-backed channel, not a distributed broker.
License
MIT