krakend / krakend-amqp

AMQP compatible backend for the KrakenD framework
https://www.krakend.io
Apache License 2.0
10 stars 16 forks source link

How to handle RPC and REST calls to the API gateway(Krakend)? #9

Open LioHub opened 3 years ago

LioHub commented 3 years ago

I'm trying to understand how to implement an api gateway that deals with microservices that expose rest and rpc endpoints.

We chose Krakend, I implemented the endpoints and configured rabbitmq, and it works, but I don't know how to give to the correct client from the queue. Can I give it back with some key? @kpacha

first way here i try set username with a queue and return the new username

{
      "endpoint": "/api/v1.0/setUserName/{reply_to}/{mess_id}/{route}",
      "method": "POST",
      "output_encoding": "json",
      "extra_config": {
        "github.com/devopsfaith/krakend/proxy": {
          "sequential": false
        }
      },
      "backend": [
        {
          "host": [
            "amqp://guest:guest@rabbitMQ:5672/"
          ],
          "url_pattern": "/",
          "encoding": "json",
          "sd": "static",
          "method": "GET",

          "disable_host_sanitize": true,
          "extra_config": {
            "github.com/devopsfaith/krakend-amqp/consume": {
              "name": "queue",
              "exchange": "exchange",
              "durable": true,
              "delete": false,
              "exclusive": false,
              "no_wait": true,
              "no_local": false,
              "routing_key": [
                "#"
              ],
              "prefetch_count": 10
            },

            "github.com/devopsfaith/krakend-amqp/produce": {
              "exchange": "exchange2",
              "durable": true,
              "delete": false,
              "exclusive": false,
              "no_wait": true,
              "mandatory": true,
              "immediate": false,
              "name": "queue2",

              "reply_to_key":"Reply_to",
              "msg_id_key":"Mess_id",
              "routing_key":"Route"
            }
          }

        }
      ]
    },

second way producer here i try set username with a queue


{
      "endpoint": "/api/v1.0/setUserName/{reply_to}/{mess_id}/{route}",
      "method": "POST",
      "headers_to_pass": ["Content-Type"],
      "backend": [
        {
          "host": [
            "amqp://guest:guest@rabbitMQ:5672/"
          ],
          "sd": "static",
          "encoding": "json",
          "disable_host_sanitize": true,
          "extra_config": {
            "github.com/devopsfaith/krakend-amqp/produce": {
              "name": "queue",
              "exchange": "exchange",
              "durable": true,
              "delete": false,
              "exclusive": false,
              "no_wait": true,
              "mandatory": true,
              "immediate": false,

              "reply_to_key":"Reply_to",
              "msg_id_key":"Mess_id",
              "routing_key":"Route"
            }
          }

        }
      ]
    },

consumer here return the new username

    {
      "endpoint": "/api/v1.0/consumer/{queue_name}/{route}",
      "method": "GET",
      "backend": [
        {
          "host": [
            "amqp://guest:guest@rabbitMQ:5672/"
          ],
          "sd": "static",
          "encoding": "json",
          "disable_host_sanitize": true,
          "extra_config": {
            "github.com/devopsfaith/krakend-amqp/consume": {
              "name": "Queue_name",
              "exchange": "exchange2",
              "durable": true,
              "delete": false,
              "exclusive": false,
              "internal": false,
              "no_wait": true,
              "no_local": false,
              "routing_key": "Route",
              "prefetch_count": 10
            }
          }
        }
      ]
    }

thanks for help)

kpacha commented 3 years ago

hi, @LioHub and welcome to the krakend community!

  1. An endpoint can't be a producer and a consumer at the same time.
  2. The consumer can't be dynamically bound to different queues or routes depending on the request. The consumer is created when starting the gateway and it fetches messages at the background

TLDR; RPC over rest+amqp is not supported (yet)

cheers!

robertotrgt commented 2 years ago

Hi, is there some progress in implementing RPC over rest+amqp? very interested in this feature.

thanks.

alombarte commented 2 years ago

Hi @robertotrgt. It's not near. KrakenD 2.0 is about to be released, but this feature is not planned for 2.0 or the next version.

ygtysr commented 1 year ago

Hi, are you considering an implementation that will handle the responses of RPC and REST calls synchronously, as in the example here?