Search documentation of macula

# macula_gateway_rpc_router (macula v0.44.2)

View Source

RPC Router Module - handles routed RPC messages (CALL/REPLY).

Responsibilities: - Process routed CALL messages delivered locally - Process routed REPLY messages delivered locally - Send REPLY back via routing path - Forward rpc_route messages to next hop - Coordinate between RPC handler, mesh, and routing modules

Pattern: Stateless delegation module - No GenServer (no state to manage) - Pure functions coordinating between modules - Consistent error handling ({ok, Result} | {error, Reason})

Extracted from macula_gateway.erl (Phase 11)

# Summary

## Functions

forward_rpc_route(NextHopNodeInfo, RpcRouteMsg, MeshPid)

Forward rpc_route message to next hop. Uses async (fire-and-forget) pattern to avoid blocking. Graceful error handling - logs errors but doesn't crash gateway.

handle_routed_call(CallMsg, RpcRouteMsg, NodeId, RpcPid, MeshPid)

Handle routed CALL message delivered locally. Looks up RPC handler, invokes it, sends reply via routing path. Authorization check added in v0.17.0.

handle_routed_reply(ReplyMsg, RpcRouteMsg, NodeId, ClientStreams)

Handle routed REPLY message delivered locally. Routes to connection via gproc (local node) or to client stream (remote client).

send_reply_via_routing(ReplyMsg, DestNodeId, NodeId, MeshPid)

Send REPLY back via routing path. Wraps reply in rpc_route envelope and routes to destination. Crashes on routing failures - exposes mesh/routing issues immediately.

# Functions

# forward_rpc_route(NextHopNodeInfo, RpcRouteMsg, MeshPid)

    -spec forward_rpc_route(map(), map(), pid()) -> ok.

Forward rpc_route message to next hop. Uses async (fire-and-forget) pattern to avoid blocking. Graceful error handling - logs errors but doesn't crash gateway.

# handle_routed_call(CallMsg, RpcRouteMsg, NodeId, RpcPid, MeshPid)

    -spec handle_routed_call(map(), map(), binary(), pid(), pid()) -> ok | {error, term()}.

Handle routed CALL message delivered locally. Looks up RPC handler, invokes it, sends reply via routing path. Authorization check added in v0.17.0.

# handle_routed_reply(ReplyMsg, RpcRouteMsg, NodeId, ClientStreams)

    -spec handle_routed_reply(map(), map(), binary(), map()) -> ok | {error, term()}.

Handle routed REPLY message delivered locally. Routes to connection via gproc (local node) or to client stream (remote client).

# send_reply_via_routing(ReplyMsg, DestNodeId, NodeId, MeshPid)

    -spec send_reply_via_routing(map(), binary(), binary(), pid()) -> ok.

Send REPLY back via routing path. Wraps reply in rpc_route envelope and routes to destination. Crashes on routing failures - exposes mesh/routing issues immediately.