Skip to content

Commit

Permalink
Merge pull request #271 from TykTechnologies/more-grpc
Browse files Browse the repository at this point in the history
Add gRPC example using HTTP/2 over TCP
  • Loading branch information
davegarvey authored Aug 8, 2024
2 parents d5dcee3 + fe2c862 commit c2a764f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
18 changes: 18 additions & 0 deletions deployments/tyk/scripts/examples/grpc/gRPC-h2c.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
20 changes: 20 additions & 0 deletions deployments/tyk/scripts/examples/grpc/hello.proto
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 3 additions & 1 deletion deployments/tyk/volumes/tyk-gateway/tyk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit c2a764f

Please sign in to comment.