This project is a simple example about How to build GRpc and Http API with Spring (without proxy).
More detail about this project at here
- Java 8
- Docker 18.09 or later
- Maven 3
# take a long time for first times to pull dependencies
DOCKER_BUILDKIT=1 docker build -t spring_grpc_http .
docker run --name spring_grpc_http --rm -d -p 6789:6789 -p 6790:6790 spring_grpc_http
# go to `core` folder, which contains pom.xml
cd core
# use maven to build
mvn clean package
# run binary by java command
java -jar target/app.jar
Use Curl to validate HTTP API
curl --location --request POST 'http:https://localhost:6789/api/ping' \
--header 'Content-Type: application/json' \
--data-raw '{
"timestamp": 20
}'
# Response:
# {
# "timestamp": "20",
# "message": "Pong"
# }
Use simple go client
go run main.go
Hardware Configurations:
- Macbook pro 2017 Intel Core i5 2.3GHz
- 16GB RAM
Results
- Throughput gRPC (6183req/s) >2x with Http (2672req/s)