Package io.grpc

Class 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.
    • 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, and target as its absolute path. We recommend libraries specify target as 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 target is preferred because it is less ambiguous. For example, the target string foo:8080 is a valid authority string with host foo and port 8080 but it is also a valid RFC 3986 URI with scheme foo and path 8080. gRPC prioritizes the URI form, which means foo:8080 will be treated as a URI with scheme foo. Using dns:///foo:8080 avoids 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 nameResolverRegistry is 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 communication
        nameResolverRegistry - the registry used to look up NameResolver providers for the target
        Returns:
        a ManagedChannelBuilder instance configured with the given parameters
        Throws:
        IllegalArgumentException - if no provider is available for the given target or credentials
        Since:
        1.83.0
      • newServerBuilderForPort

        public static ServerBuilder<?> newServerBuilderForPort​(int port,
                                                               ServerCredentials creds)
        Static factory for creating a new ServerBuilder.
        Parameters:
        port - the port to listen on
        creds - the server identity