diff --git a/deployments/tyk/data/tyk-dashboard/1/apis/api-oas-d76cfcb7f4d14c38419336a27c6ed9ca.json b/deployments/tyk/data/tyk-dashboard/1/apis/api-oas-d76cfcb7f4d14c38419336a27c6ed9ca.json new file mode 100644 index 00000000..46027026 --- /dev/null +++ b/deployments/tyk/data/tyk-dashboard/1/apis/api-oas-d76cfcb7f4d14c38419336a27c6ed9ca.json @@ -0,0 +1,43 @@ +{ + "components": {}, + "info": { + "title": "gRPC H2C", + "version": "1.0.0" + }, + "openapi": "3.0.3", + "paths": {}, + "servers": [ + { + "url": "http://tyk-gateway.localhost:8080/hello.HelloService/" + } + ], + "x-tyk-api-gateway": { + "info": { + "dbId": "66b4dec4ec7a380001d0085e", + "id": "d76cfcb7f4d14c38419336a27c6ed9ca", + "name": "gRPC H2C", + "orgId": "5e9d9544a1dcd60001d0ed20", + "state": { + "active": true + } + }, + "middleware": { + "global": { + "contextVariables": { + "enabled": true + }, + "trafficLogs": { + "enabled": true + } + } + }, + "server": { + "listenPath": { + "value": "/hello.HelloService/" + } + }, + "upstream": { + "url": "h2c://grpcbin:9000" + } + } +} diff --git a/deployments/tyk/scripts/examples/grpc/gRPC-h2c.sh b/deployments/tyk/scripts/examples/grpc/gRPC-h2c.sh new file mode 100755 index 00000000..867547b7 --- /dev/null +++ b/deployments/tyk/scripts/examples/grpc/gRPC-h2c.sh @@ -0,0 +1,18 @@ + +#!/bin/bash + +# This example uses grpcurl to call a gRPC API service proxied by the Tyk gateway using HTTP/2 over TLS (h2c). + +# Check if grpcurl is installed +if ! command -v grpcurl &> /dev/null +then + echo "grpcurl is not installed. Please install grpcurl to proceed:" + echo "brew install grpcurl" + exit 1 +fi + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROTO_FILE="${SCRIPT_DIR}/hello.proto" + +echo "Call gRPC service using HTTP/2 over TLS (h2c)" +grpcurl -plaintext -import-path "$SCRIPT_DIR" -proto "$PROTO_FILE" -d '{"greeting":"ralph"}' tyk-gateway.localhost:8080 hello.HelloService/SayHello diff --git a/deployments/tyk/scripts/examples/gRPC-api.sh b/deployments/tyk/scripts/examples/grpc/gRPC-tcp.sh similarity index 97% rename from deployments/tyk/scripts/examples/gRPC-api.sh rename to deployments/tyk/scripts/examples/grpc/gRPC-tcp.sh index c5ec29b3..1655a788 100755 --- a/deployments/tyk/scripts/examples/gRPC-api.sh +++ b/deployments/tyk/scripts/examples/grpc/gRPC-tcp.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This example uses grpcurl to call gRPC API services proxied by the Tyk gateway. +# This example uses grpcurl to call gRPC API services proxied by the Tyk gateway using TCP. # Port 9002 proxies to insecure gRPC (note -plaintext flag) # Port 9003 proxies to secure gRPC (note -insecure flag, due to self-signed certificate) diff --git a/deployments/tyk/scripts/examples/grpc/hello.proto b/deployments/tyk/scripts/examples/grpc/hello.proto new file mode 100644 index 00000000..3a2a4818 --- /dev/null +++ b/deployments/tyk/scripts/examples/grpc/hello.proto @@ -0,0 +1,20 @@ +// based on https://grpc.io/docs/guides/concepts.html + +syntax = "proto2"; + +package hello; + +service HelloService { + rpc SayHello(HelloRequest) returns (HelloResponse); + rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse); + rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse); + rpc BidiHello(stream HelloRequest) returns (stream HelloResponse); +} + +message HelloRequest { + optional string greeting = 1; +} + +message HelloResponse { + required string reply = 1; +} \ No newline at end of file diff --git a/deployments/tyk/volumes/tyk-gateway/tyk.conf b/deployments/tyk/volumes/tyk-gateway/tyk.conf index 45c3e2a8..fffae459 100755 --- a/deployments/tyk/volumes/tyk-gateway/tyk.conf +++ b/deployments/tyk/volumes/tyk-gateway/tyk.conf @@ -119,8 +119,10 @@ "certificates": [], "server_name": "", "min_version": 0, - "flush_interval": 0 + "flush_interval": 0, + "enable_http2": true }, + "proxy_enable_http2": true, "service_discovery": { "default_cache_timeout": 0 },