# `PhoenixMicro.RPC`
[🔗](https://github.com/iamkanishka/phoenix_micro/blob/v1.0.0/lib/phoenix_micro/rpc.ex#L1)

Request-response RPC over any configured transport.

Each RPC call:

1. Generates a unique `correlation_id`.
2. Publishes the request to `service_topic` with a `reply_to` inbox topic.
3. Subscribes temporarily to the inbox topic.
4. Waits for a response matching the correlation ID.
5. 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

# `call`

```elixir
@spec call(String.t(), term(), keyword()) ::
  {:ok, term()} | {:error, :timeout} | {:error, term()}
```

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.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `respond`

```elixir
@spec respond(String.t(), term(), String.t()) :: :ok
```

Sends a response back to an RPC caller.
Should be called from a consumer's `handle/2` when `message.reply_to` is set.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
