### Start HelloWorld Server Source: https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md Build and start the example hello-world server. ```sh $ cd examples/ $ ./gradlew installDist $ build/install/examples/bin/hello-world-server ``` -------------------------------- ### Run Hello World Server with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Execute the Hello World server example after building with Gradle. Ensure the server is running before starting the client. ```bash $ ./build/install/examples/bin/hello-world-server ``` -------------------------------- ### Build and Run Maven Example Source: https://github.com/grpc/grpc-java/blob/master/examples/example-debug/README.md Commands to build the hello-world example client using Maven and then run the debuggable server and standard client. ```bash mvn verify # Run the server (from the example-debug directory) mvn exec:java -Dexec.mainClass=io.grpc.examples.debug.HostnameServer # In another terminal run the client (from the examples directory) cd .. mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient ``` -------------------------------- ### Run XDS Server (With Credentials) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-xds/README.md Starts the XDS-enabled example server with the --xds-creds flag to authorize XDS security. Requires GRPC_XDS_BOOTSTRAP environment variable to be set. ```bash export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json ./build/install/example-xds/bin/xds-hello-world-server --xds-creds ``` -------------------------------- ### Run XDS Server (No Credentials) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-xds/README.md Starts the XDS-enabled example server. Requires GRPC_XDS_BOOTSTRAP environment variable to be set. ```bash export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json ./build/install/example-xds/bin/xds-hello-world-server ``` -------------------------------- ### Run the gRPC Reflection Example Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-reflection/README.md Starts the gRPC reflection example server on the default port 50051. This server provides information about its services at runtime. ```bash $ ./build/install/example-reflection/bin/reflection-server ``` -------------------------------- ### Build gRPC Example Distribution Source: https://github.com/grpc/grpc-java/blob/master/examples/example-alts/README.md Run this command in the example directory to build the distribution, which creates executable scripts for the server and client. ```bash ../gradlew installDist ``` -------------------------------- ### Build and Run Examples with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Build gRPC Java examples using Maven and run the Hello World server. The client must be run in a separate terminal. ```bash $ mvn verify $ # Run the server $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldServer ``` -------------------------------- ### Build Examples with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Use this command to build gRPC Java examples using Gradle. This generates executable scripts for clients and servers. ```bash $ ./gradlew installDist ``` -------------------------------- ### Build and Run Examples with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Build gRPC Java examples using Bazel and run the Hello World server. The client must be run in a separate terminal. ```bash $ bazel build :hello-world-server :hello-world-client $ # Run the server $ bazel-bin/hello-world-server ``` -------------------------------- ### Run ORCA Example Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-orca/README.md Start the ORCA enabled example server on its default port (50051). This command assumes you are in the grpc-java/examples/examples-orca directory. ```bash ./build/install/example-orca/bin/custom-backend-metrics-server ``` -------------------------------- ### Build Dualstack Example with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/example-dualstack/README.md Builds the dualstack example server and client using Gradle. This command generates executable scripts in the installDist directory. ```bash $ ../gradlew installDist ``` -------------------------------- ### Run gRPC Proxy with Route Guide Example Source: https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/grpcproxy/README.md Execute these commands in separate terminals to run the gRPC server, proxy, and client. The client connects to the proxy, which then forwards requests to the server. ```bash ./build/install/examples/bin/route-guide-server ``` ```bash ./build/install/examples/bin/grpc-proxy ``` ```bash ./build/install/examples/bin/route-guide-client localhost:8981 ``` -------------------------------- ### Build and Run with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-gauth/README.md Instructions for building the gRPC Java examples using Maven and running the GoogleAuthClient. ```bash $ mvn verify $ # Run the client $ mvn exec:java -Dexec.mainClass=io.grpc.examples.googleAuth.GoogleAuthClient -Dexec.args="projects/xyz123" ``` -------------------------------- ### Start Android Emulator Source: https://github.com/grpc/grpc-java/blob/master/android-interop-testing/README.md Use the provided script to start an Android Virtual Device (AVD) and wait for it to be ready. ```bash $ ./start-emulator.sh & ./wait-for-emulator.sh ``` -------------------------------- ### Install Android SDK Command Line Tools Source: https://github.com/grpc/grpc-java/blob/master/COMPILING.md Sets up the Android SDK directory and installs command-line tools. Ensure to accept licenses afterward. Add the ANDROID_HOME export to your shell configuration. ```sh export ANDROID_HOME=$HOME/Android/Sdk # Adjust to your liking mkdir $HOME/Android mkdir $ANDROID_HOME mkdir $ANDROID_HOME/cmdline-tools unzip -d $ANDROID_HOME/cmdline-tools DOWNLOADS/commandlinetools-*.zip mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest # Android SDK is now ready. Now accept licenses so the build can auto-download packages $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses # Add 'export ANDROID_HOME=$HOME/Android/Sdk' to your .bashrc or equivalent ``` -------------------------------- ### Run Hello World Client with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Execute the Hello World client example after building with Gradle. This requires the server to be running. ```bash $ ./build/install/examples/bin/hello-world-client ``` -------------------------------- ### Run Hello-World Client with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md This command runs the hello-world client using Maven. Navigate to the parent examples directory before executing. ```bash $ cd .. $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient ``` -------------------------------- ### Run ORCA Example Client Source: https://github.com/grpc/grpc-java/blob/master/examples/example-orca/README.md Execute the ORCA enabled example client. Provide a name for the greeting and a time period in milliseconds for the client to run before shutting down. ```bash ./build/install/example-orca/bin/custom-backend-metrics-client "orca tester" 1500 ``` -------------------------------- ### Build gRPC OpenTelemetry Example Source: https://github.com/grpc/grpc-java/blob/master/examples/example-opentelemetry/README.md Use this Gradle command to build the example distribution. It creates runnable scripts for the client and server. ```bash $"../gradlew installDist" ``` -------------------------------- ### Run ALTS Hello World Client Source: https://github.com/grpc/grpc-java/blob/master/examples/example-alts/README.md Execute this command to start the ALTS Hello World client. This should be run in a separate terminal after the server has started. ```bash ./build/install/example-alts/bin/hello-world-alts-client ``` -------------------------------- ### Build and Run gRPC Java Example with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Build the gRPC Java example using Maven and execute the server and client with specified arguments. ```bash $ mvn verify $ # Run the server $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldServerTls -Dexec.args="50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key" $ # In another terminal run the client $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldClientTls -Dexec.args="localhost 50440 ../../testing/src/main/resources/certs/ca.pem" ``` -------------------------------- ### Build and Run gRPC Java Example with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Build the gRPC Java example using Bazel and execute the server and client with specified arguments. ```bash $ bazel build :hello-world-tls-server :hello-world-tls-client $ # Run the server $ ../bazel-bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key $ # In another terminal run the client $ ../bazel-bin/hello-world-tls-client localhost 50440 ../../testing/src/main/resources/certs/ca.pem ``` -------------------------------- ### Build and Run with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/example-gauth/README.md Instructions for building the gRPC Java examples using Bazel and running the GoogleAuthClient. ```bash $ bazel build :google-auth-client $ # Run the client $ ../bazel-bin/google-auth-client projects/xyz123 ``` -------------------------------- ### Run JWT Authentication Example with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/example-jwt-auth/README.md Executes the JWT authentication example. First, run the server with a specified port, then run the client with server connection details and user information. ```bash # Run the server: ./build/install/example-jwt-auth/bin/auth-server 50051 # In another terminal run the client ./build/install/example-jwt-auth/bin/auth-client localhost 50051 userA clientB ``` -------------------------------- ### Run Hello World Client with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Execute the Hello World client example using Maven. This requires the server to be running in another terminal. ```bash $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient ``` -------------------------------- ### Install gRPC Java App Source: https://github.com/grpc/grpc-java/blob/master/examples/android/README.md Installs the Android gRPC client application. Ensure you are in the 'helloworld' or 'routeguide' directory before running the command. ```sh $ cd helloworld # or "cd routeguide" $ ../../gradlew installDebug ``` -------------------------------- ### Install Android App Source: https://github.com/grpc/grpc-java/blob/master/android-interop-testing/README.md Install the debug version of the Android app onto a connected device or emulator using Gradle. ```bash $ ../gradlew installDebug ``` -------------------------------- ### Run Hello World Client with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/README.md Execute the Hello World client example using Bazel. This requires the server to be running in another terminal. ```bash $ bazel-bin/hello-world-client ``` -------------------------------- ### Run ALTS Hello World Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-alts/README.md Execute this command to start the ALTS Hello World server. This requires the build distribution to be created first. ```bash ./build/install/example-alts/bin/hello-world-alts-server ``` -------------------------------- ### Generate Release Notes Starting Point Source: https://github.com/grpc/grpc-java/blob/master/RELEASING.md Generate a starting point for the release notes by listing commits since the last release and backported commits. This command helps in compiling the release notes for the new version. ```bash echo "## gRPC Java $MAJOR.$MINOR.0 Release Notes" && echo && \ git shortlog -e --format='%s (%h)' "$(git merge-base upstream/v$MAJOR.$((MINOR-1)).x upstream/v$MAJOR.$MINOR.x)"..upstream/v$MAJOR.$MINOR.x | cat && \ echo && echo && echo "Backported commits in previous release:" && \ git log --oneline "$(git merge-base v$MAJOR.$((MINOR-1)).0 upstream/v$MAJOR.$MINOR.x)"..v$MAJOR.$((MINOR-1)).0^ ``` -------------------------------- ### Run JWT Authentication Example with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-jwt-auth/README.md Executes the JWT authentication example using Maven. This involves running the AuthServer and AuthClient main classes with appropriate arguments. ```bash $ # Run the server $ mvn exec:java -Dexec.mainClass=io.grpc.examples.authentication.AuthServer -Dexec.args="50051" $ # In another terminal run the client $ mvn exec:java -Dexec.mainClass=io.grpc.examples.authentication.AuthClient -Dexec.args="localhost 50051 userA clientB" ``` -------------------------------- ### Start gRPC Test Server Source: https://github.com/grpc/grpc-java/blob/master/android-interop-testing/README.md Execute the test server script to initiate the gRPC test server. ```bash $ ../run-test-server.sh ``` -------------------------------- ### Build and Run Dualstack Server with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-dualstack/README.md Verifies the example and runs the dualstack server using Maven. This command executes the main class for the server. ```bash $ mvn verify $ # Run the server in one terminal $ mvn exec:java -Dexec.mainClass=io.grpc.examples.dualstack.DualStackServer ``` -------------------------------- ### Install libxcrypt-compat on Fedora Source: https://github.com/grpc/grpc-java/blob/master/SECURITY.md If you are on Fedora 30 or later and encounter a 'libcrypt.so.1: cannot open shared object file' error, install the libxcrypt-compat package to resolve the missing dependency. ```bash dnf -y install libxcrypt-compat ``` -------------------------------- ### Build gRPC-Java Source: https://github.com/grpc/grpc-java/blob/master/COMPILING.md Run this command in the project root to build gRPC-Java. Ensure JDK 8 is installed. ```bash ./gradlew build ``` -------------------------------- ### Run Observability Client Source: https://github.com/grpc/grpc-java/blob/master/examples/example-gcp-observability/README.md Starts the observability-enabled gRPC client. Requires setting the GRPC_GCP_OBSERVABILITY_CONFIG_FILE environment variable to the client configuration. ```bash export GRPC_GCP_OBSERVABILITY_CONFIG_FILE=src/main/resources/io/grpc/examples/gcpobservability/gcp_observability_client_config.json $ ./build/install/example-gcp-observability/bin/gcp-observability-client ``` -------------------------------- ### Run Debuggable Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-debug/README.md Execute this command to start the debuggable hostname server. It will listen for incoming gRPC requests. ```bash ./build/install/example-debug/bin/hostname-debuggable-server ``` -------------------------------- ### Run Observability Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-gcp-observability/README.md Starts the observability-enabled gRPC server. Requires setting the GRPC_GCP_OBSERVABILITY_CONFIG_FILE environment variable to the server configuration. ```bash export GRPC_GCP_OBSERVABILITY_CONFIG_FILE=src/main/resources/io/grpc/examples/gcpobservability/gcp_observability_server_config.json $ ./build/install/example-gcp-observability/bin/gcp-observability-server ``` -------------------------------- ### Build Servlet WAR File Source: https://github.com/grpc/grpc-java/blob/master/examples/example-servlet/README.md In the example directory, use Gradle to build the WAR file for the servlet server. This WAR file will be deployed to a Servlet 4.0 compatible container. ```bash ../gradlew war ``` -------------------------------- ### Run opentelemetry-server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-opentelemetry/README.md The server accepts optional arguments for server-port and prometheus-port. Ensure the server is running before starting the client. ```bash USAGE: opentelemetry-server [server-port [prometheus-port]] ``` -------------------------------- ### Run XDS Client (With Credentials) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-xds/README.md Runs the XDS-enabled example client with the --xds-creds flag to authorize XDS security. Requires GRPC_XDS_BOOTSTRAP environment variable to be set. ```bash export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json ./build/install/example-xds/bin/xds-hello-world-client --xds-creds "xds world" xds:///yourServersName ``` -------------------------------- ### Run gRPC Auth Server Source: https://github.com/grpc/grpc-java/blob/master/examples/example-oauth/README.md Starts the gRPC authentication server. It can optionally accept a port number as an argument. ```bash USAGE: auth-server [port] ``` ```bash # Run the server: ./build/install/example-oauth/bin/auth-server 50051 ``` -------------------------------- ### List a specific method with details Source: https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md Use grpc_cli ls with the -l flag to get detailed information about a specific method. ```sh $ ./grpc_cli ls localhost:50051 helloworld.Greeter.SayHello -l ``` -------------------------------- ### Run XDS Client (No Credentials) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-xds/README.md Runs the XDS-enabled example client. Requires GRPC_XDS_BOOTSTRAP environment variable to be set. The second argument specifies the target using the xds: scheme. ```bash export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json ./build/install/example-xds/bin/xds-hello-world-client "xds world" xds:///yourServersName ``` -------------------------------- ### Run Hello World TLS Server (No Mutual Auth) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Execute the TLS server without mutual authentication. Ensure the server is running before starting the client. ```bash ./build/install/example-tls/bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key ``` -------------------------------- ### Log into Google Cloud Source: https://github.com/grpc/grpc-java/blob/master/gae-interop-testing/README.md Authenticates your local environment with Google Cloud. Ensure you have the Google Cloud SDK installed and `gcloud` in your PATH. ```bash gcloud auth login ``` -------------------------------- ### Run gRPC Auth Client Source: https://github.com/grpc/grpc-java/blob/master/examples/example-oauth/README.md Starts the gRPC authentication client. It accepts optional arguments for server host, server port, user name, and client ID. ```bash USAGE: auth-client [server-host [server-port [user-name [client-id]]]] ``` ```bash # In another terminal run the client ./build/install/example-oauth/bin/auth-client localhost 50051 userA clientB ``` -------------------------------- ### Download and Build Protobuf (Linux/Mac/MinGW) Source: https://github.com/grpc/grpc-java/blob/master/COMPILING.md Steps to download, configure, and build Protobuf version 22.5 or later, required for the C++ code generation plugin. Ensure you have a C++ compiler and autotools installed. ```bash PROTOBUF_VERSION=22.5 curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz cd protobuf-$PROTOBUF_VERSION ./configure --disable-shared make # You may want to pass -j to make this run faster; see make --help sudo make install ``` -------------------------------- ### Configure Visual C++ Protobuf Properties for Gradle Source: https://github.com/grpc/grpc-java/blob/master/COMPILING.md When building on Windows with Visual C++, use these Gradle properties to specify the include and library paths for your Protobuf installation. Adjust paths as necessary. ```bash .\gradlew publishToMavenLocal \ -PvcProtobufInclude=C:\path\to\protobuf\src \ -PvcProtobufLibs=C:\path\to\protobuf\vsprojects\Release \ -PtargetArch=x86_32 ``` -------------------------------- ### Install Conscrypt Provider Source: https://github.com/grpc/grpc-java/blob/master/SECURITY.md Installs the Conscrypt security provider at a specific index. This is a prerequisite for using Conscrypt with gRPC. ```java import org.conscrypt.Conscrypt; import java.security.Security; ... // Somewhere in main() Security.insertProviderAt(Conscrypt.newProvider(), 1); ``` -------------------------------- ### Run Standard Hello World Client Source: https://github.com/grpc/grpc-java/blob/master/examples/example-debug/README.md Use this command to run the standard hello-world client. It can interact with the debuggable server and show results. ```bash ../build/install/examples/bin/hello-world-client ``` -------------------------------- ### Build Server and Client with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md Use Bazel to build both the hello-world client and the hostname server. This command should be run from the `grpc-java/examples` directory. ```bash $ bazel build :hello-world-client example-hostname:hostname-server ``` -------------------------------- ### Run HelloWorldClient Source: https://github.com/grpc/grpc-java/blob/master/examples/example-servlet/README.md Execute the HelloWorldClient application, specifying the name to greet and the server address. Ensure the servlet container is running and accessible at the specified address. ```bash ./build/install/examples/bin/hello-world-client World localhost:8080 ``` -------------------------------- ### Run Hello-World Client with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md This command runs the hello-world client in a separate terminal to interact with the hostname server. It assumes the client is built using Gradle. ```bash $ ../build/install/examples/bin/hello-world-client ``` -------------------------------- ### Install codegen to Maven local repository Source: https://github.com/grpc/grpc-java/blob/master/compiler/README.md Compile the gRPC Java codegen and install it to your local Maven repository using Gradle. This makes the codegen available to any build tool that uses Maven repositories. ```bash ../gradlew publishToMavenLocal ``` -------------------------------- ### Install gcompat on Alpine Linux Source: https://github.com/grpc/grpc-java/blob/master/SECURITY.md On Alpine Linux, if you encounter a crash in netty_tcnative due to a missing symbol, install the gcompat package. Then, use the LD_PRELOAD environment variable when executing Java to load the compatibility library. ```bash apk install gcompat LD_PRELOAD=/lib/libgcompat.so.0 ``` -------------------------------- ### Run Hello-World Client with Bazel Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md Execute the hello-world client built with Bazel. This command should be run in a separate terminal from the server. ```bash $ ./bazel-bin/hello-world-client ``` -------------------------------- ### Get Service Descriptor for TestDeprecatedService Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/testLite/golden/TestDeprecatedService.java.txt Retrieves the singleton ServiceDescriptor for TestDeprecatedService. This descriptor contains metadata about the service and its methods. ```java public static io.grpc.ServiceDescriptor getServiceDescriptor() { io.grpc.ServiceDescriptor result = serviceDescriptor; if (result == null) { synchronized (TestDeprecatedServiceGrpc.class) { result = serviceDescriptor; if (result == null) { serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) .addMethod(getDeprecatedMethodMethod()) .build(); } } } return result; } ``` -------------------------------- ### Run Hello World TLS Client (Mutual Auth) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Connect to the TLS server from the client with mutual authentication. Client certificate and key are provided for server verification. ```bash ./build/install/example-tls/bin/hello-world-tls-client localhost 50440 ../../testing/src/main/resources/certs/ca.pem ../../testing/src/main/resources/certs/client.pem ../../testing/src/main/resources/certs/client.key ``` -------------------------------- ### gRPC Service Descriptor Accessor Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/test/golden/TestDeprecatedService.java.txt This code provides a thread-safe way to get the ServiceDescriptor for TestDeprecatedService. It ensures that the descriptor is initialized only once. ```java private static volatile io.grpc.ServiceDescriptor serviceDescriptor; public static io.grpc.ServiceDescriptor getServiceDescriptor() { io.grpc.ServiceDescriptor result = serviceDescriptor; if (result == null) { synchronized (TestDeprecatedServiceGrpc.class) { result = serviceDescriptor; if (result == null) { serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) .setSchemaDescriptor(new TestDeprecatedServiceFileDescriptorSupplier()) .addMethod(getDeprecatedMethodMethod()) .build(); } } } return result; } ``` -------------------------------- ### Build and Run Hostname Server with Maven Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md These Maven commands build the project and then execute the hostname server. The `exec:java` goal is used to run the main class. ```bash $ mvn verify $ # Run the server (from the examples-hostname directory) $ mvn exec:java -Dexec.mainClass=io.grpc.examples.hostname.HostnameServer ``` -------------------------------- ### Get Idempotent Call Method Descriptor Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/testLite/golden/TestService.java.txt Retrieves the method descriptor for the IdempotentCall method. It ensures thread-safe initialization of the descriptor. ```java io.grpc.MethodDescriptor getIdempotentCallMethod; if ((getIdempotentCallMethod = TestServiceGrpc.getIdempotentCallMethod) == null) { synchronized (TestServiceGrpc.class) { if ((getIdempotentCallMethod = TestServiceGrpc.getIdempotentCallMethod) == null) { TestServiceGrpc.getIdempotentCallMethod = getIdempotentCallMethod = io.grpc.MethodDescriptor.newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName(SERVICE_NAME, "IdempotentCall")) .setIdempotent(true) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.compiler.Test.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.compiler.Test.SimpleResponse.getDefaultInstance())) .build(); } } } return getIdempotentCallMethod; ``` -------------------------------- ### Hello World TLS Client Usage Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Command-line arguments for the TLS-enabled Hello World client. Client certificate and key are only needed for mutual authentication. ```text USAGE: HelloWorldClientTls host port [trustCertCollectionFilePath [clientCertChainFilePath clientPrivateKeyFilePath]] Note: clientCertChainFilePath and clientPrivateKeyFilePath are only needed if mutual auth is desired. ``` -------------------------------- ### List a specific service with details Source: https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md Use grpc_cli ls with the -l flag to get detailed information about a specific service. ```sh $ ./grpc_cli ls localhost:50051 helloworld.Greeter -l ``` -------------------------------- ### Hello World TLS Server Usage Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Command-line arguments for the TLS-enabled Hello World server. The trustCertCollectionFilePath is optional and only required for mutual TLS. ```text USAGE: HelloWorldServerTls port certChainFilePath privateKeyFilePath [trustCertCollectionFilePath] Note: You only need to supply trustCertCollectionFilePath if you want to enable Mutual TLS. ``` -------------------------------- ### Build gRPC Benchmarks Source: https://github.com/grpc/grpc-java/blob/master/benchmarks/README.md Builds the benchmark executables for gRPC. Run this from the grpc-java directory. ```bash ./gradlew :grpc-benchmarks:installDist ``` -------------------------------- ### Get TestService Descriptor in Java Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/test/golden/TestService.java.txt Retrieves the singleton instance of the gRPC service descriptor for TestService. This method ensures thread-safe initialization. ```java public static io.grpc.ServiceDescriptor getServiceDescriptor() { io.grpc.ServiceDescriptor result = serviceDescriptor; if (result == null) { synchronized (TestServiceGrpc.class) { result = serviceDescriptor; if (result == null) { serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) .setSchemaDescriptor(new TestServiceFileDescriptorSupplier()) .addMethod(getUnaryCallMethod()) .addMethod(getStreamingOutputCallMethod()) .addMethod(getStreamingInputCallMethod()) .addMethod(getFullBidiCallMethod()) .addMethod(getHalfBidiCallMethod()) .addMethod(getImportMethod()) .addMethod(getSafeCallMethod()) .addMethod(getIdempotentCallMethod()) .build(); } } } return result; } ``` -------------------------------- ### Get Import MethodDescriptor in Java Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/test/golden/TestService.java.txt Retrieves the MethodDescriptor for the Import RPC. This method also supports bidirectional streaming and uses StreamingInputCallRequest and StreamingInputCallResponse. ```java private static volatile io.grpc.MethodDescriptor getImportMethod; @io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "Import", requestType = io.grpc.testing.compiler.Test.StreamingInputCallRequest.class, responseType = io.grpc.testing.compiler.Test.StreamingInputCallResponse.class, methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) public static io.grpc.MethodDescriptor getImportMethod() { io.grpc.MethodDescriptor getImportMethod; if ((getImportMethod = TestServiceGrpc.getImportMethod) == null) { synchronized (TestServiceGrpc.class) { if ((getImportMethod = TestServiceGrpc.getImportMethod) == null) { TestServiceGrpc.getImportMethod = getImportMethod = io.grpc.MethodDescriptor.newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Import")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.compiler.Test.StreamingInputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.compiler.Test.StreamingInputCallResponse.getDefaultInstance())) .setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("Import")) .build(); } } } return getImportMethod; } ``` -------------------------------- ### Publish gRPC-Java Artifacts to Maven Local Source: https://github.com/grpc/grpc-java/blob/master/COMPILING.md Execute this command to install the built artifacts into your local Maven repository, making them available for use in other projects. ```bash ./gradlew publishToMavenLocal ``` -------------------------------- ### Run Hostname Server with Gradle Source: https://github.com/grpc/grpc-java/blob/master/examples/example-hostname/README.md Execute this command to run the hostname server after building it with Gradle. Ensure you are in the correct directory. ```bash $ ./build/install/hostname-server/bin/hostname-server ``` -------------------------------- ### List all methods of a specific gRPC service Source: https://github.com/grpc/grpc-java/blob/master/examples/example-reflection/README.md Uses gRPCurl to list all methods available within a specified gRPC service. Replace 'helloworld.Greeter' with the desired service name. ```bash $ grpcurl -plaintext localhost:50051 list helloworld.Greeter ``` -------------------------------- ### Run Hello World TLS Server (Mutual Auth) Source: https://github.com/grpc/grpc-java/blob/master/examples/example-tls/README.md Execute the TLS server with mutual authentication enabled. The CA certificate is provided to verify client certificates. ```bash ./build/install/example-tls/bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key ../../testing/src/main/resources/certs/ca.pem ``` -------------------------------- ### Get HalfBidiCall MethodDescriptor in Java Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/test/golden/TestService.java.txt Retrieves the MethodDescriptor for the HalfBidiCall RPC. This method is designed for bidirectional streaming and uses specific request and response types. ```java @io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "HalfBidiCall", requestType = io.grpc.testing.compiler.Test.StreamingOutputCallRequest.class, responseType = io.grpc.testing.compiler.Test.StreamingOutputCallResponse.class, methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) public static io.grpc.MethodDescriptor getHalfBidiCallMethod() { io.grpc.MethodDescriptor getHalfBidiCallMethod; if ((getHalfBidiCallMethod = TestServiceGrpc.getHalfBidiCallMethod) == null) { synchronized (TestServiceGrpc.class) { if ((getHalfBidiCallMethod = TestServiceGrpc.getHalfBidiCallMethod) == null) { TestServiceGrpc.getHalfBidiCallMethod = getHalfBidiCallMethod = io.grpc.MethodDescriptor.newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName(SERVICE_NAME, "HalfBidiCall")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.compiler.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.compiler.Test.StreamingOutputCallResponse.getDefaultInstance())) .setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("HalfBidiCall")) .build(); } } } return getHalfBidiCallMethod; } ``` -------------------------------- ### Get StreamingInputCall Method Descriptor Source: https://github.com/grpc/grpc-java/blob/master/compiler/src/testLite/golden/TestService.java.txt Retrieves the method descriptor for the client streaming 'StreamingInputCall' RPC. This descriptor is used internally by gRPC to manage the RPC. ```java io.grpc.testing.compiler.Test.StreamingInputCallResponse> getStreamingInputCallMethod() { io.grpc.MethodDescriptor getStreamingInputCallMethod; if ((getStreamingInputCallMethod = TestServiceGrpc.getStreamingInputCallMethod) == null) { synchronized (TestServiceGrpc.class) { if ((getStreamingInputCallMethod = TestServiceGrpc.getStreamingInputCallMethod) == null) { TestServiceGrpc.getStreamingInputCallMethod = getStreamingInputCallMethod = io.grpc.MethodDescriptor.newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName(SERVICE_NAME, "StreamingInputCall")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.compiler.Test.StreamingInputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.compiler.Test.StreamingInputCallResponse.getDefaultInstance())) .build(); } } } return getStreamingInputCallMethod; } ```