Crate hedwig[][src]

Expand description

Hedwig is a message bus library that works with arbitrary pubsub services such as AWS SNS/SQS or Google Cloud Pubsub. Messages are validated before they are published. The publisher and consumer are de-coupled and fan-out is supported out of the box.

The Rust library currently only supports publishing.


Publish a message. Payload encoded with JSON and validated using a JSON Schema.

use hedwig::{validators, Publisher, Consumer};

#[derive(Clone, PartialEq, Eq, prost::Message)]
struct UserCreatedMessage {
    #[prost(string, tag = "1")]
    user_id: String,

impl<'a> hedwig::EncodableMessage for UserCreatedMessage {
    type Error = validators::ProstValidatorError;
    type Validator = validators::ProstValidator;
    fn topic(&self) -> hedwig::Topic {
    fn encode(&self, validator: &Self::Validator) -> Result<hedwig::ValidatedMessage, Self::Error> {

impl hedwig::DecodableMessage for UserCreatedMessage {
    type Error = validators::ProstDecodeError<validators::prost::SchemaMismatchError>;
    type Decoder =

    fn decode(msg: hedwig::ValidatedMessage, decoder: &Self::Decoder) -> Result<Self, Self::Error> {

let publisher = /* Some publisher */
let consumer = /* Consumer associated to that publisher */

let mut publish_sink = Publisher::<UserCreatedMessage>::publish_sink(publisher, validators::ProstValidator::new());
let mut consumer_stream = consumer.consume::<UserCreatedMessage>(

publish_sink.send(UserCreatedMessage { user_id: String::from("U_123") }).await?;



Adapters for using GCP’s PubSub as a message service for hedwig

mocktest or mock

In-memory messaging implementations, meant to imitate distributed messaging services for test purposes.

Implementations of validators.


A received message which can be acknowledged to prevent re-delivery by the backing message service.

Like futures_util::sink::Drain but implements Default

The stream returned by the consume function

A message queue topic name to which messages can be published

A validated message.


All errors that may be returned when operating top level APIs.


A token associated with some message received from a message service, used to issue an ack/nack/modify request

Message consumers ingest messages from a queue service and present them to the user application as a Stream.

Messages which can be decoded from a ValidatedMessage stream.

Types that can be encoded and published.

Message publishers.

Type Definitions

Custom headers associated with a message.