Class Grpc
- java.lang.Object
-
- io.grpc.Grpc
-
public final class Grpc extends Object
Stuff that are part of the public API but are not bound to particular classes, e.g., static methods, constants, attribute and context keys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGrpc.TransportAttrAnnotation for transport attributes.
-
Field Summary
Fields Modifier and Type Field Description static CallOptions.Key<String>CALL_OPTION_CUSTOM_LABELThe value for the custom label of per-RPC metrics.static Attributes.Key<SocketAddress>TRANSPORT_ATTR_LOCAL_ADDRAttribute key for the local address of a transport.static Attributes.Key<SocketAddress>TRANSPORT_ATTR_REMOTE_ADDRAttribute key for the remote address of a transport.static Attributes.Key<SSLSession>TRANSPORT_ATTR_SSL_SESSIONAttribute key for SSL session of a transport.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ManagedChannelBuilder<?>newChannelBuilder(String target, ChannelCredentials creds)Creates a channel builder with a target string and credentials.static ManagedChannelBuilder<?>newChannelBuilder(String target, ChannelCredentials creds, NameResolverRegistry nameResolverRegistry)Creates a channel builder with a target string, credentials, and a specific name resolver registry.static ManagedChannelBuilder<?>newChannelBuilderForAddress(String host, int port, ChannelCredentials creds)Creates a channel builder from a host, port, and credentials.static ServerBuilder<?>newServerBuilderForPort(int port, ServerCredentials creds)Static factory for creating a new ServerBuilder.
-
-
-
Field Detail
-
TRANSPORT_ATTR_REMOTE_ADDR
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710") @TransportAttr public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_REMOTE_ADDR
Attribute key for the remote address of a transport.
-
TRANSPORT_ATTR_LOCAL_ADDR
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710") @TransportAttr public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_LOCAL_ADDR
Attribute key for the local address of a transport.
-
TRANSPORT_ATTR_SSL_SESSION
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710") @TransportAttr public static final Attributes.Key<SSLSession> TRANSPORT_ATTR_SSL_SESSION
Attribute key for SSL session of a transport.
-
CALL_OPTION_CUSTOM_LABEL
public static final CallOptions.Key<String> CALL_OPTION_CUSTOM_LABEL
The value for the custom label of per-RPC metrics. Defaults to empty string when unset. Must not be set tonull.
-
-
Method Detail
-
newChannelBuilder
public static ManagedChannelBuilder<?> newChannelBuilder(String target, ChannelCredentials creds)
Creates a channel builder with a target string and credentials. The target can be either an RFC 3986 URI, or an authority string.Example URIs:
"dns:///foo.googleapis.com:8080""dns:///foo.googleapis.com""dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443""dns://8.8.8.8/foo.googleapis.com:8080""dns://8.8.8.8/foo.googleapis.com""zookeeper://zk.example.com:9900/example_service""intent:#Intent;package=com.some.app;action=a;category=c;end;"
An authority string will be converted to a URI having the scheme of the name resolver with the highest priority (e.g.
"dns"), the empty string as the authority, andtargetas its absolute path. We recommend libraries specifytargetas a URI instead since they cannot know which NameResolver will be default at runtime. Example authority strings:"localhost""127.0.0.1""localhost:8080""foo.googleapis.com:8080""127.0.0.1:8080""[2001:db8:85a3:8d3:1319:8a2e:370:7348]""[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"
The URI form of
targetis preferred because it is less ambiguous. For example, the target stringfoo:8080is a valid authority string with hostfooand port8080but it is also a valid RFC 3986 URI with schemefooand path8080. gRPC prioritizes the URI form, which meansfoo:8080will be treated as a URI with schemefoo. Usingdns:///foo:8080avoids this ambiguity.
-
newChannelBuilder
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/12694") public static ManagedChannelBuilder<?> newChannelBuilder(String target, ChannelCredentials creds, NameResolverRegistry nameResolverRegistry)
Creates a channel builder with a target string, credentials, and a specific name resolver registry.The provided
nameResolverRegistryis used to resolve the target address into physical addresses (e.g., DNS or custom schemes).- Parameters:
target- the target URI for the channel, such as"localhost:8080"or"dns:///example.com"creds- the channel credentials to use for secure communicationnameResolverRegistry- the registry used to look upNameResolverproviders for the target- Returns:
- a
ManagedChannelBuilderinstance configured with the given parameters - Throws:
IllegalArgumentException- if no provider is available for the given target or credentials- Since:
- 1.83.0
-
newChannelBuilderForAddress
public static ManagedChannelBuilder<?> newChannelBuilderForAddress(String host, int port, ChannelCredentials creds)
Creates a channel builder from a host, port, and credentials. The host and port are combined to form an authority string and then passed tonewChannelBuilder(String, ChannelCredentials). IPv6 addresses are properly surrounded by square brackets ("[]").
-
newServerBuilderForPort
public static ServerBuilder<?> newServerBuilderForPort(int port, ServerCredentials creds)
Static factory for creating a new ServerBuilder.- Parameters:
port- the port to listen oncreds- the server identity
-
-