3d55f189c0
Iter 22. Cierra el set de hoy: future-me (o cualquier nuevo collab)
levanta el escenario completo con un comando.
crates/apps/brahman-demo/ con 3 binarios:
- brahman-demo-broker: Server::bind standalone con Broker. Reemplaza
a ente-zero para demos (ente-zero es PID 1 con kernel surface,
child subreaper, bus, brain, audit — overkill).
- brahman-demo-producer: Card con flow.output[demo-stream:json].
- brahman-demo-consumer: Card con flow.input[demo-feed:json] —
mismo type → matchea con producer.
Env vars en los 3: BRAHMAN_INIT_SOCKET, BRAHMAN_BROKER_CONTEXT,
BRAHMAN_DEMO_LABEL/FLOW/TYPE, RUST_LOG.
scripts/bootstrap-demo.sh:
- Modes: all (default) / broker / only.
- Cleanup-safe: trap mata todos los PIDs spawneados (SIGTERM grace
+ SIGKILL fallback) y borra el socket.
- Espera al socket antes de spawnear (evita ENOENT en handshake).
- Logs separados por proceso bajo $BRAHMAN_DEMO_LOG_DIR.
Smoke end-to-end (sin DISPLAY): consumer recibe MatchEvent
{ Available, demo-feed ← demo-stream, via: Exact, pinned: false }
automáticamente cuando entra el producer. Match fluye por el push
channel del broker.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.3 KiB
Rust
69 lines
2.3 KiB
Rust
//! `brahman-demo-broker` — broker standalone para demos.
|
|
//!
|
|
//! ente-zero (PID 1) es el broker "real" pero pesa toneladas
|
|
//! (kernel surface, child subreaper, bus, brain, audit, etc). Este
|
|
//! binario sólo arma `brahman_handshake::Server::bind` con un broker
|
|
//! configurado, escucha en el socket default, y corre forever.
|
|
//!
|
|
//! Suficiente para que el script de bootstrap (y los 4 explorers)
|
|
//! tengan algo a qué conectarse sin necesitar el bootstrap PID 1
|
|
//! completo.
|
|
//!
|
|
//! Variables de entorno respetadas:
|
|
//! - `BRAHMAN_INIT_SOCKET` — path del Unix socket. Default: el
|
|
//! resuelto por `brahman_handshake::transport::default_socket_path`.
|
|
//! - `BRAHMAN_BROKER_CONTEXT` — context bias del broker (igual que
|
|
//! ente-zero); afecta priority_contexts si las Cards lo declaran.
|
|
//! - `RUST_LOG` — filtro de tracing (default `info`).
|
|
|
|
use std::sync::Arc;
|
|
|
|
use brahman_broker::{Broker, BrokerConfig, MatchStrategy};
|
|
use brahman_handshake::server::{Server, ServerConfig};
|
|
use brahman_handshake::transport;
|
|
use tokio::sync::Mutex;
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
async fn main() -> std::io::Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
)
|
|
.init();
|
|
|
|
let context = std::env::var("BRAHMAN_BROKER_CONTEXT").ok();
|
|
let broker = Arc::new(Mutex::new(Broker::new(BrokerConfig {
|
|
strategy: MatchStrategy::default(),
|
|
current_context: context.clone(),
|
|
})));
|
|
|
|
let socket = transport::default_socket_path();
|
|
tracing::info!(
|
|
socket = %socket.display(),
|
|
context = ?context,
|
|
"brahman-demo-broker arranca"
|
|
);
|
|
|
|
let server = Server::bind(
|
|
&socket,
|
|
ServerConfig {
|
|
init_attached: false,
|
|
broker: Some(broker),
|
|
net: None,
|
|
policy: None,
|
|
},
|
|
)?;
|
|
|
|
// Loop accept-forever. Cada conexión va a su propia tokio task —
|
|
// sesiones independientes, ninguna bloquea a las otras.
|
|
loop {
|
|
let session = server.accept_one().await?;
|
|
tokio::spawn(async move {
|
|
if let Err(e) = session.handle().await {
|
|
tracing::warn!(?e, "session terminó con error");
|
|
}
|
|
});
|
|
}
|
|
}
|