Skip to main content

Crate mako_engine

Crate mako_engine 

Source
Expand description

mako-engine — event-sourced process runtime for German energy market communication (MaKo).

§Architecture

Raw EDIFACT bytes (AS4 transport)
        │
        ▼
[edi-energy] parse · validate
        │
        ▼  Command (typed, validated)
EngineContext::spawn / ::resume → Process::execute / ::execute_with / ::execute_with_retry
        │
        ├─ load events → reconstruct state (Workflow::apply + upcast)
        ├─ handle command (Workflow::handle — pure, deterministic)
        └─ append EventEnvelope batch (optimistic concurrency)

EventStore ──► ProjectionRunner ──► Read models
SnapshotStore ──► Process::state_with_snapshot (O(k) replay)
OutboxStore ──► delivery worker ──► AS4 endpoint
DeadlineStore ──► scheduler ──► TimeoutDeadline command
ProcessRegistry ──► inbound message routing ──► Process

§Quick start

use mako_engine::{
    builder::EngineBuilder,
    ids::TenantId,
    version::WorkflowId,
    event_store::InMemoryEventStore,
};

let ctx = EngineBuilder::new()
    .with_event_store(InMemoryEventStore::new())
    .build();

// Spawn a new process.
let process = ctx.spawn::<MyWorkflow>(TenantId::new(), WorkflowId::new("…", "FV2024-10-01"));
let envelopes = process.execute(my_command).await?;

// Reconstruct typed state by replaying all events.
let state = process.state().await?;

// Persist routing information and resume on the next message.
ctx.registry().register(tenant, &conv_id.to_string(), process.identity()).await?;
let identity = ctx.registry().lookup(tenant, &conv_id.to_string()).await?.unwrap();
let resumed  = ctx.resume::<MyWorkflow>(identity);

§Crate modules

ModuleContents
idsTyped identifier newtypes (EventId, StreamId, ProcessId, ProcessIdentity, DeadlineId, …)
typesSemantic domain identifiers (MaLo, MeLo, MarktpartnerCode, MessageRef, DeviceId, BkvId, UenbId, BillingPeriod)
versionFormatVersion, WorkflowId, and WorkflowVersionPolicy
envelopeEventEnvelope and NewEvent
errorEngineError, WorkflowError
event_storeEventStore trait (with stream_version) + InMemoryEventStore
workflowWorkflow trait, EventPayload, CommandContext
message_adapterMessageAdapter trait, AdapterRegistry, FnAdapter — cross-FV command translation
processProcess<W,S> — ergonomic typed process handle
projectionProjection trait + ProjectionRunner (single-stream and multi-stream) + GlobalProjectionCheckpoint
snapshotSnapshot, SnapshotStore + InMemorySnapshotStore / NoopSnapshotStore
outboxOutboxMessage, OutboxStore + InMemoryOutboxStore / NoopOutboxStore
inboxInboxStore trait + InMemoryInboxStore for AS4 retry deduplication
deadlineDeadline, DeadlineStore + InMemoryDeadlineStore / NoopDeadlineStore
registryProcessRegistry + InMemoryProcessRegistry / NoopProcessRegistry
pid_routerPidRouter — maps Prüfidentifikator values to workflow names
fristenRegulatory deadline helpers: add_hours (GPKE 24h), add_werktage (WiM/GeLi/MABIS)
dead_letterDeadLetterSink trait + LogDeadLetterSink / NoopDeadLetterSink
erpErpAdapter, ErpCommandSource, ErpEvent — ERP/backend integration contract (BO4E)
builderEngineModule trait, EngineBuilder, EngineContext

Modules§

builder
EngineModule trait, EngineBuilder, and EngineContext.
dead_letter
Dead-letter sink for unroutable or unprocessable inbound messages.
deadline
Deadline tracking for regulatory process timers.
envelope
The EventEnvelope — the standard wrapper for every persisted event.
erp
ERP integration traits and reference implementations.
error
Engine-level error types.
event_store
EventStore trait and the in-process [InMemoryEventStore] implementation.
fristen
Regulatory deadline calculation helpers.
ids
Typed identifier newtypes for all engine-layer concepts.
inbox
Inbox deduplication for inbound messages.
marktrolle
BDEW Rollenmodell — market-participant role configuration.
message_adapter
MessageAdapter — cross-format-version message-to-command translation.
metrics
EngineMetrics — process-level event counters for Prometheus export.
migration
In-flight process state migration across BDEW format-version boundaries.
outbox
Outbox pattern for reliable at-least-once outbound message delivery.
partner
Trading-partner master data — the PartnerStore trait and supporting types.
pid_router
PID-to-workflow routing table.
process
Process — ergonomic typed handle for a single MaKo process instance.
profile
Profile requirements — decouple domain crates from edi-energy.
projection
Projection trait and ProjectionRunner.
registry
Process routing registry.
snapshot
Snapshotting support — a performance optimisation for long event streams.
types
Semantic domain type wrappers for identifiers used across all MaKo process families.
version
Workflow versioning types.
workflow
Workflow trait, EventPayload, CommandPayload, and CommandContext.

Macros§

bo4e_schema_url
Construct a BO4E v202501.0.0 JSON Schema URL for a Business Object.