Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LioHub opened this issue Apr 6, 2021 · 4 comments
Open

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

LioHub opened this issue Apr 6, 2021 · 4 comments

Comments

@LioHub
Copy link

LioHub commented Apr 6, 2021

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

  • Expose REST endpoints to the client. Internally route to the REST or RPC microservices
  • Expose REST and RPC endpoints to the client, route as necessary

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
Copy link
Member

kpacha commented Apr 6, 2021

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
Copy link

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

thanks.

@alombarte
Copy link
Member

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
Copy link

ygtysr commented Jun 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants