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
Balancer:Balancerfor load balancing.Core:Address,Protocol,Error,Result.Discovery:Registryfor service discovery.Gateway:Gatewayfor network communication.Message:Envelope,Headers,Payload,Reply.Infra:Cache,Middleware.Queue:Queueand delivery semantics.Routing:Routerfor message routing.Service:ServiceandProcessortraits.
§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§
Structs§
- Address
- Uniform Resource Identifier for BakBon.
- Balancer
- Load balancer.
- Cache
- Envelope
- Application-level message wrapper with
Headers,RouteandPayload. - Queue
- Registry
- Immutable registry of services keyed by address.
- Router
- Routes
Envelopes to registeredServicewith load balancing.
Enums§
- Error
- Errors that can occur in bakbon operations.
- Protocol
- Transport protocol used in BakBon addresses and gateways.
Traits§
- Gateway
Gatewayis a network endpoint that can send messages to otherServices.- 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.
- Service
Box - A boxed service that can be cloned and processed.
- Service
Map - A map of service vectors indexed by service name.
- Service
Vec - A vector of boxed services.