CoAkka Runtime · Bun 3.3.2
Configure CoAkka Runtime with Bun
Choose the task you are doing. Beginner can stop at Embedded and defaults. Open network, route, TLS or data-lane settings only when the deployment needs them. Read Core-accepted values instead of reconstructing effective state from input.
What are you configuring?
Environment and packageBun 1.3.14+ · bun
bun --version- Bun 1.3.14 or newer is required, matching the package 3.3.2 engine floor.
bun add [email protected]- Installs the exact Bun connector used in this lesson, including native payloads for published targets.
.mjs- Uses ESM and imports through the package root. Do not deep-import internal transport modules.
COAKKA_RUNTIME_LIB- An explicit native-library diagnostic override. Normal package use does not need it; any override must match the connector.
Start the hostBunRuntimeHost.start(startSpec)
systemName- The stable logical system name.
nodeId- A unique instance ID in that system. One Bun process may keep one active host.
routes- The initial route snapshot.
localRoute(target)is the in-process helper. generation- The route snapshot generation. Omission starts with a valid generation; later updates must be newer.
network- Omit it to let Core select Embedded. Use an explicit helper when the lesson needs to show topology.
queueCapacity- A queue bound. Omit it for Core's default and tune only with pressure evidence.
strictNoDrop- Requests explicit refusal rather than a permitted drop policy. Read it back through
runtimeStartupConfig(). enableMonitortrueenables extra collection,falseis explicit disable intent, and omission preserves Core's default.separateDeliveredRequestLane- The default is shaped for request/reply. Override only for a measured one-way host.
overloadPolicy- Advanced ingress/local/remote policy. Omit the group to retain Core-owned defaults.
connectionStrategy/security- Advanced transport groups. Omit the entire group so zero does not accidentally become explicit intent.
Bytes-first callaskPayload(source, target, payload, timeoutMs?, deliveryHint?)
source- The caller's logical name, such as
checkout. target- The work address matching a route and handler, such as
orders.quote. payload- A
Uint8ArrayorBuffer. Both application sides own the byte schema and encoding. timeoutMs- The call deadline in milliseconds. The lesson uses 2000; choose the application contract.
deliveryHint- Omit it or use
DeliveryHint.ROUTER_DEFAULTto follow the route. Other hints constrain delivery; they are not retry policy. DeadletterError- A structured terminal failure. Read reason, envelope, generation and failure facts; do not parse the message.
Network participationembeddedNetwork · outboundOnlyNetwork · networkBun
embeddedNetwork()- Opens no listener; caller and handler remain in one process. Start here.
outboundOnlyNetwork()- Connects to peers without accepting peer requests.
networkBun(bindHost, bindPort, advertiseHost, advertisePort?)- Opens a local listener and advertises a peer-reachable endpoint.
bindHost/bindPort- The socket actually opened on the host.
advertiseHost/advertisePort- The endpoint placed in peer routes. Loopback is not reachable across two machines.
Choose direct peers, edge or Kubernetes · Understand shared connectivity
Routes and endpointsRouteSpec · EndpointSpec
target- The capability name being resolved.
endpoints- Candidate owners, each with host, port, weight and flags.
RouteStrategy.SINGLE_OWNER- Exactly one owner endpoint in the snapshot.
WEIGHTED_ROUND_ROBIN- Distributes work by weight across available endpoints.
RENDEZVOUS_HASH- Selects a stable endpoint from a route key;
routeKeyHintnames the header containing it. weight- Endpoint weight for a weighted strategy; it is not a retry count.
EndpointFlag.LOCAL- The endpoint belongs to this process;
UNAVAILABLEremoves it from new work. flags- Route and endpoint flags are contract bitsets. Use exported enums; do not invent meanings for numbers.
Look up routing, ROUND_ROBIN, WEIGHT and the full checklist.
Connections and securityRuntimeTcpConnectionStrategySpec · RuntimeTcpSecuritySpec
- Omitted
connectionStrategy - Preserves Core's
MULTIPLEXINGdefault. An object withmode: 0is explicitPER_EXCHANGEintent. modePER_EXCHANGE,BOUNDED_POOL,PERSISTENT_SINGLE_FLIGHTorMULTIPLEXING; check capabilities first.maxConnections- Bounds connections where the selected mode and capability support tuning.
maxRequestsPerConnection- Retires a connection after a bounded number of requests.
idleTimeoutMs- Bounds idle connection retention.
security.mode- PLAINTEXT, TLS or MUTUAL_TLS according to the trust boundary and capabilities.
credentialGeneration- A nonzero, increasing generation for each new credential set.
credentialId- A non-secret diagnostic ID; never place keys or tokens here.
caCertificateFile- The trusted CA PEM used to verify the peer.
identityCertificateFile/privateKeyFile- The instance certificate chain and matching private key. Never log key material.
reloadMode- How existing connections are handled when a newer credential generation is applied.
Look up defaults and validation · Look up TLS/mTLS and checklists
File Lane and Stream LaneResources independent from RuntimeHost
FileLane.openOwned- An exact-owner receiver can issue a
FileReceiveGrantpinned to instance, address, port and transfer. FileLane.sha256- Computes exact size and SHA-256 before prepare.
waitTransfer- Waits from the last update sequence. Success requires terminal SEND and RECEIVE records. Put this loop in a Worker or process when the app has an event loop.
StreamLane.openOwned- An exact-owner publisher issues a
StreamPublishGrantfor one session. maxFrameBytes/initialWindowBytes- Bound frames and receive credit; the window must fit at least one frame.
push/end- Place frames and the end marker into the bounded publisher mailbox;
falsemeans it cannot accept more yet. poll- Returns one copied subscriber frame, or
nullwhen none is ready. Worker- File waits and Stream mailbox loops can block the event loop. Keep each lane owner entirely inside its Worker or process.
forget/close- Record terminal outcomes, then forget records. File Lane close returns a Promise; Bun Stream Lane close is synchronous.
Read Core-accepted configurationruntimeStartupConfig · runtimeConfig · runtimeNetworkConfig
Create configuration.mjs in the lesson project, paste the file and run it. Queue 64, strict-no-drop, Embedded and Monitor are explicit only to distinguish requested and accepted state.
configuration.mjs
import { BunRuntimeHost, embeddedNetwork, localRoute } from "coakka-runtime-bun";
const runtime = BunRuntimeHost.start({
systemName: "configuration-lab",
nodeId: "configuration-lab-1",
routes: [localRoute("orders.quote")],
network: embeddedNetwork(),
strictNoDrop: true,
queueCapacity: 64,
enableMonitor: true,
});
try {
const startup = runtime.runtimeStartupConfig();
const active = runtime.runtimeConfig();
const network = runtime.runtimeNetworkConfig();
console.log(
`generation=${active.appliedGeneration} queue_capacity=${startup.queueCapacity} ` +
`strict_no_drop=${startup.strictNoDrop} monitor=${startup.monitorEnabled} ` +
`network_mode=${network.mode}`,
);
} finally {
await runtime.close();
}
Terminal
bun run configuration.mjsVerified output
generation=1 queue_capacity=64 strict_no_drop=true monitor=true network_mode=1
runtimeStartupConfig()- Applied startup defaults, queue, CPU/I/O, connection, delivery and Monitor state.
runtimeConfig()- Generation, route count, runtime state, bind and effective overload policy.
runtimeNetworkConfig()- Network mode, explicit/default provenance and bind/advertise state.
runtimeCapabilities()- Compiled, entitled and effective feature bits before advanced transport changes.
health()/stats()- Current copied health and counters.
runtimeSnapshot()- A combined runtime, startup, network, connector, health and stats diagnostic view.