Skip to main content

Crate bakbon

Crate bakbon 

Source
Expand description

BakBon - Infrastructure Microkernel for Distributed Systems

BakBon provides protocol-agnostic building blocks for message-driven distributed systems. Build microservices, IoT networks, or blockchain infrastructure with composable, type-safe components.

§Modules

§Quick Example

use bakbon::prelude::*;

    // Create addresses.
    let source = Address::parse("http://client-address.com");
    let destination = Address::parse("grpc://service.com/echo");
    assert!(source.is_ok());
    assert!(destination.is_ok());
    let src = source.unwrap();
    let dst = destination.unwrap();

    // Create a payload from the bytes crate.
    let payload = Payload::from("Hello there");

    // Create a message envelope.
    let message = Envelope::new(src, dst.clone() , payload);

    // Create a service.
    #[derive(Debug)]
    struct NilService(Address);

    impl Service for NilService {
        fn address(&self) -> &Address { &self.0 }
        fn duplicate(&self) -> ServiceBox { Box::new(Self(self.0.clone())) }
        fn process(&self, msg: Envelope) -> Result<Reply> { Ok(None) }
    }

    let service = NilService(dst);

    // Create a service registry.
    let registry = Registry::builder()
        .register(service)
        .build();

    // Create a router.
    let mut router = Router::builder()
        .registry(registry)
        .build();

    // Route the created message.
    let reply = router.route(message);
    assert!(reply.is_ok());
    let reply = reply.unwrap();
    assert!(reply.is_none());

Re-exports§

pub use bytes;

Modules§

prelude

Structs§

Address
Uniform Resource Identifier for BakBon.
Balancer
Load balancer.
Cache
Envelope
Application-level message wrapper with Headers, Route and Payload.
Queue
Registry
Immutable registry of services keyed by address.
Router
Routes Envelopes to registered Service with load balancing.

Enums§

Error
Errors that can occur in bakbon operations.
Protocol
Transport protocol used in BakBon addresses and gateways.

Traits§

Gateway
Gateway is a network endpoint that can send messages to other Services.
Middleware
Example:
Processor
Service
A service that processes envelopes and returns replies.
Storage

Type Aliases§

Headers
Message metadata attached to an Envelope
Payload
Message payload attached to an Envelope
ProcMap
Reply
Optional reply message returned by a Processor
Result
Result type for bakbon operations.
ServiceBox
A boxed service that can be cloned and processed.
ServiceMap
A map of service vectors indexed by service name.
ServiceVec
A vector of boxed services.