@@ -15,10 +15,11 @@ defmodule Hyper.Grpc do
1515
1616 ## Serving
1717
18- The server is started by `Hyper.Application` when enabled in config. It is
19- stateless and may run on every node; placement and routing are cluster-wide.
20- See `Hyper.Grpc.Config` for configuration — operators own the listener (port,
21- TLS, adapter options) entirely from their own `config/`.
18+ The server is always started by `Hyper.Application` — it is a core interface,
19+ not an add-on, and an idle listener costs next to nothing. It is stateless and
20+ runs on every node; placement and routing are cluster-wide. See
21+ `Hyper.Grpc.Config` for configuration — operators own the listener (port, TLS,
22+ adapter options) entirely from their own `config/`.
2223
2324 ## Connecting from the BEAM
2425
@@ -35,58 +36,50 @@ defmodule Hyper.Grpc do
3536 gRPC server configuration, read from application env:
3637
3738 config :hyper, Hyper.Grpc,
38- enabled: true,
3939 port: 50_051,
4040 # any other GRPC.Server.Supervisor option, e.g. TLS:
4141 cred: GRPC.Credential.new(ssl: [certfile: "/path/cert.pem", keyfile: "/path/key.pem"])
4242
43- `:enabled` (default `false`) gates whether the server starts. Every other
44- key is passed straight through to `GRPC.Server.Supervisor`, so operators
45- control the listener — port, TLS credentials, adapter options, body limits —
46- entirely from their own config. Hyper prescribes nothing beyond defaulting
47- `:port` and pointing the supervisor at `Hyper.Grpc.Endpoint`.
43+ The server always runs (it is a core interface, not opt-in); this config
44+ only tunes the listener. Every key is passed straight through to
45+ `GRPC.Server.Supervisor`, so operators control port, TLS credentials,
46+ adapter options, and body limits entirely from their own config. Hyper
47+ prescribes nothing beyond defaulting `:port` and pointing the supervisor at
48+ `Hyper.Grpc.Endpoint`.
4849
4950 Load secrets however you like: put cert/key paths in `config/runtime.exs` and
5051 build the credential there, or read them from a vault — Hyper never touches
5152 the filesystem on your behalf.
53+
54+ > #### Co-located nodes {: .info}
55+ >
56+ > Every node binds `:port`. Running multiple nodes on one host (e.g. a local
57+ > cluster) requires giving each a distinct port via its own config.
5258 """
5359
5460 @ default_port 50_051
5561
56- @ doc "Whether the gRPC server should start."
57- @ spec enabled? ( ) :: boolean ( )
58- def enabled? , do: Keyword . get ( all ( ) , :enabled , false )
59-
6062 @ doc """
6163 The options spliced into the `GRPC.Server.Supervisor` child: the operator's
62- config minus `:enabled` , with the endpoint, `start_server`, and a default
63- port filled in if absent.
64+ config, with the endpoint, `start_server`, and a default port filled in if
65+ absent.
6466 """
6567 @ spec server_options ( ) :: keyword ( )
6668 def server_options do
67- all ( )
68- |> Keyword . delete ( :enabled )
69+ Application . get_env ( :hyper , Hyper.Grpc , [ ] )
6970 |> Keyword . put_new ( :endpoint , Hyper.Grpc.Endpoint )
7071 |> Keyword . put_new ( :start_server , true )
7172 |> Keyword . put_new ( :port , @ default_port )
7273 end
73-
74- @ spec all ( ) :: keyword ( )
75- defp all , do: Application . get_env ( :hyper , Hyper.Grpc , [ ] )
7674 end
7775
7876 @ doc """
79- The supervisor children for the gRPC server: empty unless the server is
80- enabled (see `Hyper.Grpc.Config`). Spliced into the app supervision tree by
81- `Hyper.Application`.
77+ The gRPC server's supervisor child. Always present — the server is a core
78+ interface, started unconditionally by `Hyper.Application`.
8279 """
83- @ spec server_children ( ) :: [ Supervisor . child_spec ( ) | { module ( ) , term ( ) } ]
80+ @ spec server_children ( ) :: [ { module ( ) , keyword ( ) } ]
8481 def server_children do
85- if Config . enabled? ( ) do
86- [ { GRPC.Server.Supervisor , Config . server_options ( ) } ]
87- else
88- [ ]
89- end
82+ [ { GRPC.Server.Supervisor , Config . server_options ( ) } ]
9083 end
9184
9285 @ doc """
0 commit comments