Skip to contents

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:port or https://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 metadata in grpc_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, so authorization is refused here: pass a token as credentials.

credentials

Call credentials from grpc_bearer_token() or grpc_call_credentials(), or NULL for none. They need an https:// URL, or an http:// one to a loopback host. Their metadata may not share a name with headers or with a call's metadata.

tls

Certificate trust settings from zuhttp::zu_tls(), for an https:// URL.

keepalive

HTTP/2 keepalive from grpc_keepalive(), or NULL for 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 from zuhttp unchanged. 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 (see metadata in grpc_call()), nor authorization. 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 as credentials. NULL builds a fresh one.

Value

A zugrpc_channel.

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)