rust-pubsub-lib provides a shared abstraction for publishing to, snapshotting from, and subscribing to broker-backed topics from Rust applications. It hides backend-specific connection details behind a small set of async traits so application code can stay focused on message handling instead of transport setup.
The primary abstractions provided by this library are the Publisher, Snapshot, and Subscriber traits.
Publisherasynchronously sends a message to a configured topic.Snapshotreads the currently available messages for a topic in one operation.Subscriberyields a stream of messages as they arrive.Messagedescribes the message shape used across all backends.
The library also provides concrete message helpers:
ByteMessagefor raw byte payloads.StringMessagefor UTF-8-oriented payloads, using lossy decoding when byte input is not valid UTF-8.
Select one or more crate features depending on the broker backend your application uses.
kafka: enableskafka_implwith Kafka-backed implementations ofPublisher,Snapshot, andSubscriber.redis-pubsub: enablesredis_impls::pubsubwith Redis pub/sub implementations ofPublisherandSubscriber.redis-stream: enablesredis_impls::streamwith Redis Stream implementations ofPublisher,Snapshot, andSubscriber.testing-utils: enables backend-specific test harness helpers such askafka_impl::testing_utilsfor tests that exercise broker-facing code.
The following environment variables are required for Kafka-backed behavior:
KAFKA_CONNECTION_SECONDS: controls the timeout used by Kafka operations inget_kafka_timeout_val().
Redis-backed implementations do not currently require a crate-specific environment variable, but they do require a valid Redis connection URI to be passed to Publisher::new(), Snapshot::get(), or Subscriber::new().
Generate the crate documentation locally with cargo doc --all-features and open the output from target/doc/. The most important API entry points are documented in src/lib.rs, with backend-specific details under src/kafka_impl/mod.rs and src/redis_impls/mod.rs.
The following packages must be present on the host machine when building this library:
cmakelibcurl4-openssl-devlibsasl2-devzlib
The configured Dev Container in .devcontainer/ has the necessary tools to build without additional installation.