Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asoorm/tyk-rmq-middleware
Example RMQ RPC middleware with Tyk
https://github.com/asoorm/tyk-rmq-middleware
grpc grpc-go plugins rabbitmq rpc tyk tyk-gateway
Last synced: 2 months ago
JSON representation
Example RMQ RPC middleware with Tyk
- Host: GitHub
- URL: https://github.com/asoorm/tyk-rmq-middleware
- Owner: asoorm
- License: mit
- Created: 2018-08-06T11:22:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-06T22:47:09.000Z (over 6 years ago)
- Last Synced: 2024-10-14T09:36:59.704Z (4 months ago)
- Topics: grpc, grpc-go, plugins, rabbitmq, rpc, tyk, tyk-gateway
- Language: Go
- Size: 2.71 MB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Get running
```
$ docker-compose up -dCreating network "tyk-rmq-middleware_default" with the default driver
Creating tyk-rmq-middleware_rmq_1 ... done
Creating tyk-rmq-middleware_worker_1 ... done
Creating tyk-rmq-middleware_middleware-grpc_1 ... done
```This will start a RMQ server listening on port `5672` for messages, and `15672` admin interface.
To access the admin interface, visit `http://localhost:15672` and login with highly secure credentials `guest:guest`.The worker is a golang app - which simply listens on the `rpc_queue` queue, and replies to messages on the `reply_to`
queue with `correlation_id` from the incoming request.## Import API definition
Import `./apidefinitions/sentence_generator.json` into Tyk Dashboard as a new API.
## See it working
```
$ curl -X POST http://localhost:8080/httpbin/post -d '{"firstName": "Ahmet"}'
{
"error": "lastName: lastName is required; age: age is required"
}
```Ok, so when we fix the request - meeting validation rules:
```
$ curl -X POST http://localhost:8080/httpbin/post -d '{"firstName": "Ahmet", "lastName": "Soormally", "age": 36}'{"sentence":"Ahmet Soormally is 36 year's old"}
```What just happened?
1. Tyk validated the incoming request with JSON Schema validate JSON plugin.
2. Tyk called gRPC middleware POST hook `MyRabbitHook`
3. `MyRabbitHook` created a temporary `reply_to` queue, with a random `correlation_id` Then sent a message to
`rpc_queue` for a worker to pick up.
4. `worker` process was listening to `rpc_queue` for messages, and when it received the message, generated the sentence
based on body contents.
5. Once it generated the response body, it placed the message onto the temporary `reply_to` queue with appropriate
`correlation_id`.## Note
This is a PoC. I would highly recommend that `middleware-grpc` didn't establish a connection & disconnect from rabbit
for every RPC call.