A channel holds what every call to one server shares: the server's
address, the headers sent on every call, the message size limit, and the
zuhttp client whose connection pool carries the calls. An http:// URL
speaks cleartext HTTP/2 with prior knowledge (h2c), for a local server.
An https:// URL negotiates HTTP/2 over TLS. gRPC has no HTTP/1.1
fallback, so the channel's client always requires HTTP/2.
Usage
grpc_channel(
url,
headers = NULL,
credentials = NULL,
tls = NULL,
keepalive = grpc_keepalive(),
max_message = 128 * 1024^2,
client = NULL
)Arguments
- url
The server, as
http://host:portorhttps://host:port. The host is a name, an IPv4 address or a bracketed IPv6 address, and the port is from 1 to 65535. No path, query or user information.- headers
Metadata sent on every call: a named character vector or a named list, as
metadataingrpc_call(), with the same reserved names. A call's own metadata replaces a channel header of the same name. Headers are part of the channel, and go wherever it is saved or sent, soauthorizationis refused here: pass a token ascredentials.- credentials
Call credentials from
grpc_bearer_token()orgrpc_call_credentials(), orNULLfor none. They need anhttps://URL, or anhttp://one to a loopback host. Their metadata may not share a name withheadersor with a call'smetadata.- tls
Certificate trust settings from
zuhttp::zu_tls(), for anhttps://URL.- keepalive
HTTP/2 keepalive from
grpc_keepalive(), orNULLfor none. The default sends a PING on a connection idle for 60 seconds and replaces it if no answer comes within 20, as Spark Connect's Python client does.- max_message
The largest response message accepted, in bytes. The default, 128 MiB, is Spark Connect's. A larger message fails the call with
RESOURCE_EXHAUSTED.- client
A
zuhttp::zu_client()to build on, so that proxies, TLS pins, middleware and test transports come fromzuhttpunchanged. The channel derives its own client from it, with HTTP/2 required, no HTTP content coding and no query. Its headers may not use a name reserved for metadata (seemetadataingrpc_call()), norauthorization. The channel holds the client and everything in it, such as a proxy URL with a password or middleware that captures a token, so keep secrets out of it and pass a token ascredentials.NULLbuilds a fresh one.
See also
grpc_call() to make a call, grpc_close() to close it.
Examples
ch <- grpc_channel("http://localhost:50051")
ch
#> <zugrpc_channel> localhost:50051
#> transport: cleartext HTTP/2 (h2c)
#> state: open
#> streams: 0 open
grpc_close(ch)