Giter Club home page Giter Club logo

tyk-rmq-middleware's Introduction

Get running

$ docker-compose up -d

Creating 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.

tyk-rmq-middleware's People

Contributors

asoorm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.