6 releases (3 breaking)

✓ Uses Rust 2018 edition

new 0.4.0 Sep 9, 2019
0.3.1 Aug 7, 2019
0.3.0 Jul 1, 2019
0.2.0 Jul 1, 2019
0.1.1 Jun 25, 2019

#5 in #microservices

Download history 61/week @ 2019-06-24 73/week @ 2019-07-01 122/week @ 2019-07-08 822/week @ 2019-07-15 592/week @ 2019-07-22 719/week @ 2019-07-29 658/week @ 2019-08-05 1062/week @ 2019-08-12 1050/week @ 2019-08-19 884/week @ 2019-08-26 490/week @ 2019-09-02

2,201 downloads per month

Apache-2.0

36KB
648 lines

Hedwig library for Rust

Build Status Latest Version Docs

What is it?

Hedwig is a inter-service communication bus that works on AWS and GCP, while keeping things pretty simple and straight forward. It uses json schema draft v4 for schema validation so all incoming and outgoing messages are validated against pre-defined schema.

Hedwig allows separation of concerns between consumers and publishers so your services are loosely coupled, and the contract is enforced by the schema validation. Hedwig may also be used to build asynchronous APIs.

Support exists for Python and Golang.

For intra-service messaging, see Taskhawk.

Quick Start

Installation

Add to Cargo.toml:

[dependencies]
hedwig = "*"

To use Google Publisher, use feature google. There's also a mock publisher provided for testing that can be accessed using feature mock.

Usage

    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 appropriately
    // let publisher = GooglePublisher::new(String::from("/home/.google-key.json"), "myproject".into())?; 

    let hedwig = Hedwig::new(
        schema,
        "myapp",
        publisher
        router,
    )?;

    let message = hedwig.message(
        MessageType::UserCreated,
        Version(MajorVersion(1), MinorVersion(0)),
        UserCreatedData { user_id: "U_123" },
    )?;

    let message_id = message.id;

    let publish_id = hedwig.publish(message)?;
    println!(
        "Published message {} with pubsub id: {}",
        message_id, publish_id
    );

There's also a full running example in the repo.

Getting Help

We use GitHub issues for tracking bugs and feature requests.

  • If it turns out that you may have found a bug, please open an issue

Dependencies

~15MB
~373K SLoC