[−][src]Crate hedwig
A Hedwig library for Rust. Hedwig is a message bus that works with AWS SNS/SQS and Google Cloud Pubsub, with messages validated using JSON schema. The publisher and consumer are de-coupled and fan-out is supported out of the box.
Examples
Publish a new message
use hedwig::{Hedwig, MajorVersion, MinorVersion, Version}; fn main() -> Result<(), failure::Error> { let schema = r#" { "$id": "https://hedwig.standard.ai/schema", "$schema": "https://json-schema.org/draft-04/schema#", "description": "Example Schema", "schemas": { "user-created": { "1.*": { "description": "A new user was created", "type": "object", "x-versions": [ "1.0" ], "required": [ "user_id" ], "properties": { "user_id": { "$ref": "https://hedwig.standard.ai/schema#/definitions/UserId/1.0" } } } } }, "definitions": { "UserId": { "1.0": { "type": "string" } } } }"#; fn router(t: MessageType, v: MajorVersion) -> Option<&'static str> { match (t, v) { (MessageType::UserCreated, MajorVersion(1)) => Some("dev-user-created-v1"), _ => None, } } // create a publisher instance let hedwig = Hedwig::new( schema, "myapp", publisher, router, )?; let message = hedwig.message( MessageType::UserCreated, Version(MajorVersion(1), MinorVersion(0)), UserCreatedData { user_id: "U_123".into() }, )?; hedwig.publish(message)?;
Structs
GooglePublisher | A publisher that uses Google PubSub. To use this class, add feature |
Hedwig | Central instance to access all Hedwig related resources |
MajorVersion | Major part component in semver |
Message | Message represents an instance of a message on the message bus. |
Metadata | Additional metadata associated with a message |
MinorVersion | Minor part component in semver |
MockPublisher | A mock publisher that doesn't publish messages, but just stores them in-memory for later verification
This is useful primarily in tests. To use this class, add feature |
Version | A semver version without patch part |
Enums
HedwigError | All errors that may be returned when instantiating a new Hedwig instance |
MessageError | All errors that may be returned while instantiating a new Message instance |
PublishError | All errors that may be returned while publishing a message |
Traits
Publisher | A trait for message publishers. This may be used to implement custom behavior such as publish to <insert your favorite cloud platform>. |
Type Definitions
Headers | Type alias for custom headers associated with a message |
MessageRouter |
|