Request-response RPC over any configured transport.
Each RPC call:
- Generates a unique
correlation_id. - Publishes the request to
service_topicwith areply_toinbox topic. - Subscribes temporarily to the inbox topic.
- Waits for a response matching the correlation ID.
- Returns
{:ok, response_payload}or{:error, reason}on timeout.
Example
# Caller side
{:ok, result} = PhoenixMicro.RPC.call("math.sum", [1, 2, 3], timeout: 3_000)
# Responder side — in a Consumer
defmodule MathConsumer do
use PhoenixMicro.Consumer
topic "math.sum"
def handle(%{payload: numbers, reply_to: reply_to, correlation_id: cid}, _ctx) do
result = Enum.sum(numbers)
PhoenixMicro.RPC.respond(reply_to, result, cid)
:ok
end
end
Summary
Functions
Performs an RPC call to topic with payload.
Returns a specification to start this module under a supervisor.
Sends a response back to an RPC caller.
Should be called from a consumer's handle/2 when message.reply_to is set.
Functions
Performs an RPC call to topic with payload.
Options:
:timeout(integer, default 5000) — milliseconds to wait for response.:retry(integer, default 0) — number of times to retry on timeout.:transport(atom) — override the transport for this call.
Returns a specification to start this module under a supervisor.
See Supervisor.
Sends a response back to an RPC caller.
Should be called from a consumer's handle/2 when message.reply_to is set.
@spec start_link(keyword()) :: GenServer.on_start()