top of page
Recent Posts
Writer's pictureassad

Continue with kong part 2

Updated: Oct 3, 2021

Before continuing with Kong part 2 please go to the earlier part which you can find here, where I describe how you can install kong as a docker container. In this part I'll be talking about adding a mock service into kong as it's backend service or you can say it's upstream.


Before starting, I would like to describe the purpose of this. Since, kong acts as a gateway for all of your microservice, you need to add a microservice behind kong. See the following picture for the concept:




Here through the kong gateway we are exposing some services and those are differentiating using uri path. Since we exposed kong proxy on 80 port (see here), the upstream url will be as follow to access the upstream services:


For monolith url will be http://localhost/path

For microservice-1 url will be http://localhost/microservice-1

For microservice-2 url will be http://localhost/microservice-2

For microservice-3 url will be http://localhost/microservice-3

For other url will be http://localhost/other-path


What is the use of this single access point. By this way we can control all of the services that are backed by kong and we can manage authentication, authorization, access rate limit, request response mapping, caching, auditing and many more. If you want to know more about what kong can do please go to https://docs.konghq.com/hub/ and there you can find what kong can do.


Now I'm going to add a mock service as a kong upstream service which is http://mockbin.org/request . First of all you need to add a kong service by running following command:


curl -s -X POST http://localhost:8001/services \    
-d name=mock-service \    
-d url=http://mockbin.org/request

Response:


{ "client_certificate": null, "connect_timeout": 60000, "created_at": 1593159373, "host": "mockbin.org", "id": "0b361bb9-274e-4c05-91ad-844b85673b25", "name": "mock-service", "path": "/request", "port": 80, "protocol": "http", "read_timeout": 60000, "retries": 5, "tags": null, "updated_at": 1593159373, "write_timeout": 60000}


Now it is time to add rout to the service, which can be done by running following curl command:


curl -s -X POST http://localhost:8001/routes \    
-d service.id=0b361bb9-274e-4c05-91ad-844b85673b25 \    
-d paths[]=/mock

Now your backend service is ready to access through kong api gateway by the following url:


That's it for today. Next I'll be writing about authentication using keyckoak. So get ready for that. Thanks.




178 views0 comments

Recent Posts

See All

Install basic kong api manager on docker

Kong is a scalable, open source API Layer (also known as an API Gateway, or API Middleware). Kong runs in front of any RESTful API and is...

Comments


Log In to Connect With Members
View and follow other members, leave comments & more.
bottom of page