CoAkka Runtime · Node.js 3.3.2
Cheat sheet CoAkka Runtime · Node.js
Tra đúng việc cần làm, copy mẫu ngắn, rồi mở file đầy đủ đã chạy thật khi cần kiểm tra lifecycle và failure path.
Version và package
Terminal
npm install [email protected]- Connector
[email protected]; Node.js 22+; import ESM từ package root.- Core generation
3.3. Hai số đầu connector xác định generation Core; số cuối là revision connector.- Native identity
- Commit
f9e5a632d2d046a5b4e89d5ce0c9042aee5c7b45, ABI 1 cho package đã kiểm chứng. - Package targets
- macOS ARM64, Linux ARM64/x64 và Windows ARM64/x64. Support phải đọc theo đúng connector version + OS + CPU + evidence, không suy rộng.
Embedded request/reply
Pattern
const runtime = RuntimeHost.start({
systemName: "orders",
nodeId: "orders-1",
routes: [localRoute("orders.quote")],
});
try {
runtime.registerPayloadHandler("orders.quote", quote);
const reply = await runtime.askPayload("checkout", "orders.quote", payload, 2000);
} finally {
await runtime.close();
}Bỏ network để giữ Core default Embedded. Mở file đầu tiên đầy đủ.
Outcome, deadletter và OneWay
- Reply
askPayload,askJsonhoặcaskTypedresolve bằng terminal response đã correlation.- Deadletter
DeadletterError.deadlettergiữ reason, envelope gốc, generation, endpoint attempts và failure facts. Không parse error text.- Timeout/cancel
- Là failure boundary riêng; không tự retry công việc có side effect khi chưa có idempotency contract.
- OneWay
sendOneWayTyped/sendOneWayJsonkhông có reply cho business acknowledgement. Admission/delivery observability không biến nó thành request/reply.- Terminal stream
submitRequest...+terminalEvents()tách submit khỏi await nhưng dùng cùng runtime contract.
Peer trực tiếp
Service
network: networkNode("0.0.0.0", 19321, "pricing.internal", 19321),
routes: [localRoute("orders.quote")],Caller route
network: outboundOnlyNetwork(),
routes: [{
target: "orders.quote",
strategy: RouteStrategy.SINGLE_OWNER,
endpoints: [{ host: "pricing.internal", port: 19321, weight: 1, flags: 0 }],
}],Bind là nơi listener mở; advertise là địa chỉ peer truy cập. Route snapshots có generation và do topology owner cấp; CoAkka Runtime không tự tuyên bố service discovery hay Kubernetes membership.
File Lane
- Tính
FileLane.sha256(sourcePath). - Receiver
openOwnedvàprepareReceiveGrant. - Chuyển grant qua control plane tin cậy; sender gọi
submitSend(grant.toSendSpec(...)). - Chờ cả
SENDvàRECEIVEterminal, kiểm tracompletedvà result. - Ghi nhận outcome,
forgethai record, rồiawait close().
Stream Lane
- Publisher
openOwned, đặtmaxFrameBytesvà prepare một source callback đồng bộ. - Subscriber dùng grant, receive window và consumer callback đồng bộ.
- Copy
datatrong callback nếu cần giữ; không retain borrowed view. - Chờ PUBLISH/SUBSCRIBE terminal, kiểm tra result, forget rồi close.
- Dùng pressure snapshots làm input cho app policy; không biến chúng thành một retry loop không bound.
Monitor và effective state
enableMonitor: true- Intent bật extra collection trước startup. Xác nhận bằng
runtime.monitor.isEnabled(). runtime.monitor.snapshot()- Health và stats đã copy tại thời điểm đọc.
awaitNext(timeoutMs)- Promise có deadline chờ tín hiệu refresh; null chỉ là không có signal trong cửa sổ.
runtimeStartupConfig()- Defaults/provenance và startup facts Core đã áp dụng.
runtimeConfig()/runtimeNetworkConfig()- Generation, routes, overload, bind và network participation thực tế.
runtimeSnapshot()- Ảnh tổng hợp cho chẩn đoán. Không log secrets hoặc token cùng snapshot.
Checklist tích hợp
- Một
RuntimeHostactive cho mỗi process Node.js; tạo ở startup, không tạo theo request. - Handler và business authorization thuộc ứng dụng; Core sở hữu routing, transport, bounds và outcome facts.
- Await mọi operation/Monitor wait trước
await runtime.close(). - Tách cài package khỏi cấu hình runtime; ghim connector version và kiểm tra package/platform tuple.
- Đọc capability và effective state trước khi bật connection mode, TLS/mTLS hoặc tuning.
- File Lane và Stream Lane là owner độc lập; đóng chúng ngay cả khi
RuntimeHostkhông tồn tại.