Giter Club home page Giter Club logo

rusty-event-broker's Introduction

RustyEventBroker

A mediator library that brokers the communication between different message transports.

๐Ÿšง This is a personal playground for learning Rust. It is a simple mediator pattern implementation. It is not intended for production use, at least not yet. ๐Ÿšง

Usage

Declare your messages.

#[message("A1RequestMessageName")]
struct A1Request {
    name: String,
    age: u8,
}

#[message("A1ResponseMessageName")]
struct A1Response {
    data: String,
}

Declare your message handler.

#[request_handler(A1RequestHandler, "A1RequestMessageName", "A1ResponseMessageName")]
fn handle_request(&self, request: Arc<A1Request>) -> Result<Arc<A1Response>, String> {
    Ok(Arc::new(A1Response {
        data: "A1 Handler Response".to_string(),
    }))
}

Add your transports and your message handlers.

let mut broker = Broker::new();

let in_memory_transport = Arc::new(InMemoryTransport::new());

in_memory_transport.register_request_handler(A1RequestHandler {});
in_memory_transport.register_request_handler(A2RequestHandler {});
in_memory_transport.register_request_handler(B1RequestHandler {});

broker.register_exit_transport(in_memory_transport.clone());
broker.register_entry_transport(in_memory_transport);

Then send your messages.

let a1_message = A1Message {
    name: "something".to_string(),
    age: 10,
};

let a1_response = broker.request::<A1Request, A1Response>(a1_message).unwrap();
assert_eq!(a1_response.data, "A1 Handler Response");

Roadmap

  • Add handlers
  • Add request support
  • Add request async support. Requires rust trait async suport
  • Add request timeout
  • Add publish support
  • Add send support
  • Improve message identification (macro?) and use as discriminator for handlers
  • Make handlers, messages the more simple and generic as possible. Create a macro to generate the boilerplate code.
  • Add transport support for in memory
  • Add transport support for RabbitMQ
  • Think about routing preferences (e.g. prefer in memory over RabbitMQ, because of performance reasons)

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.