channel

fun channel(hostName: String = "", port: Int = -1, enableRetry: Boolean = true, maxRetryAttempts: Int = 5, tlsContext: TlsContext = PLAINTEXT_CONTEXT, overrideAuthority: String = "", inProcessServerName: String = "", block: ManagedChannelBuilder<*>.() -> Unit): ManagedChannel

Builds a ManagedChannel using either a Netty transport or an in-process transport.

When inProcessServerName is non-empty, an in-process channel is created, ignoring hostName, port and tlsContext. The retry and authority options apply to both transports.

Return

the built ManagedChannel

Parameters

hostName

the target server hostname (Netty transport only)

port

the target server port (Netty transport only)

enableRetry

whether gRPC retry is enabled on the channel. true (the default) matches grpc-java's own default: RPCs get transparent retries (e.g. on a refused stream during a server restart), and any retry policy in the channel's service config applies. false calls disableRetry(), which turns off transparent retries as well. Configured retries need a retry policy, supplied in block through defaultServiceConfig(...); this flag alone does not add one.

maxRetryAttempts

the maximum number of retry attempts per RPC; a negative value leaves grpc's own default in place

tlsContext

the TLS configuration for the channel; defaults to PLAINTEXT_CONTEXT

overrideAuthority

overrides the authority used for TLS hostname verification

inProcessServerName

if non-empty, creates an in-process channel with this name

block

a configuration block applied to the channel builder before building

Throws

if the Netty transport is chosen and hostName is blank or port is not in 0..65535