### Running gRPC Server Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Command to start the gRPC server application using Gradle. This server exposes the 'HelloService'. ```Shell ./gradlew :grpc-server:bootRun ``` -------------------------------- ### Running Spring Cloud Gateway Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Command to start the Spring Cloud Gateway application using Gradle. This gateway routes gRPC requests. ```Shell ./gradlew :grpc-simple-gateway:bootRun ``` -------------------------------- ### Running gRPC Client Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Command to start the gRPC client application using Gradle. This client sends requests to the gRPC service via the gateway. ```Shell ./gradlew :grpc-client:bootRun ``` -------------------------------- ### Spring Cloud Gateway Route for gRPC Traffic Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Example route configuration for Spring Cloud Gateway to redirect gRPC traffic. It matches paths starting with 'grpc', forwards to a specified URI, and adds a custom response header. ```YAML spring: cloud: gateway: routes: - id: grpc uri: https://localhost:6565 predicates: - Path=/grpc/** filters: - AddResponseHeader=X-Request-header, header-value ``` -------------------------------- ### gRPC Gateway Response Example Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Shows the expected HTTP response from the gRPC JSON gateway after processing a JSON request, including the updated Content-Type header and the transformed payload. ```bash < HTTP/2 200 < content-type: application/json < content-length: 34 < * Connection #0 to host localhost left intact {"greeting":"Hello, Duff McKagan"} ``` -------------------------------- ### Sending JSON Request via cURL Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Example of sending a POST request with a JSON payload to the gRPC JSON gateway using cURL, demonstrating the interaction with the custom filter. ```bash curl -XPOST 'https://localhost:8091/json/hello' -d '{"firstName":"Duff","lastName":"McKagan"}' -k -H"Content-Type: application/json" -v ``` -------------------------------- ### Spring Cloud Gateway Route for All Traffic Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc A simplified route configuration for Spring Cloud Gateway that forwards all incoming traffic to the gRPC server and adds a response header. This is used in the end-to-end example. ```YAML routes: - id: grpc uri: https://localhost:6565 predicates: - Path=/** filters: - AddResponseHeader=X-Request-header, header-value ``` -------------------------------- ### Running the gRPC Gateway Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Instructions on how to build and run the Spring Cloud Gateway application with the gRPC integration using Gradle. ```shell ./gradlew :grpc-json-gateway:bootRun ``` -------------------------------- ### Import JKS to PKCS12 Keystore Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/grpc-server/README.md Imports an existing JKS keystore ('keystore.jks') into a PKCS12 keystore ('keystore.p12'). ```shell keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.p12 -deststoretype pkcs12 ``` -------------------------------- ### gRPC Protocol Buffer Definition Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Defines a simple gRPC service 'HelloService' with a 'hello' RPC method. It uses Protocol Buffers for message serialization, defining 'HelloRequest' and 'HelloResponse' messages. ```Protobuf syntax = "proto3"; message HelloRequest { string firstName = 1; string lastName = 2; } message HelloResponse { string greeting = 1; } service HelloService { rpc hello(HelloRequest) returns (HelloResponse); } ``` -------------------------------- ### Enable HTTP/2 and SSL in Spring Cloud Gateway Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc Configuration to enable HTTP/2 and SSL for gRPC communication in Spring Cloud Gateway. Requires a keystore file for secure connections. ```YAML server: http2: enabled: true ssl: key-store-type: PKCS12 key-store: classpath:keystore.p12 key-store-password: password key-password: password enabled: true ``` -------------------------------- ### Generate RSA Keypair (JKS) Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/grpc-server/README.md Generates a new RSA key pair with a 2048-bit key size, stored in a JKS keystore file named 'keystore.jks'. The validity period is set to 3650 days. ```shell keytool -genkeypair -keyalg RSA -keysize 2048 -keystore keystore.jks -validity 3650 ``` -------------------------------- ### Generate RSA Keypair (PKCS12) Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/grpc-server/README.md Generates a new RSA key pair with a 2048-bit key size, stored in a PKCS12 keystore file named 'keystore.p12'. The validity period is set to 3650 days. ```shell keytool -genkeypair -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keystore.p12 -validity 3650 ``` -------------------------------- ### Custom JSON to gRPC Filter Source: https://github.com/albertoimpl/spring-cloud-gateway-grpc/blob/main/README.adoc A custom Spring Cloud Gateway filter that deserializes a JSON request, creates a gRPC channel, sends a message to a gRPC server, and serializes the gRPC response back to JSON. ```java static class GRPCResponseDecorator extends ServerHttpResponseDecorator { @Override public Mono writeWith(Publisher body) { exchange.getResponse().getHeaders().set("Content-Type", "application/json"); URI requestURI = exchange.getRequest().getURI(); ManagedChannel channel = createSecuredChannel(requestURI.getHost(), 6565); return getDelegate().writeWith(deserializeJSONRequest() .map(jsonRequest -> { String firstName = jsonRequest.getFirstName(); String lastName = jsonRequest.getLastName(); return HelloServiceGrpc.newBlockingStub(channel) .hello(HelloRequest.newBuilder() .setFirstName(firstName) .setLastName(lastName) .build()); }) .map(this::serialiseJSONResponse) .map(wrapGRPCResponse()) .cast(DataBuffer.class) .last()); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.