Micro Services, Apigateway and Kong

Source: Internet
Author: User
Tags cassandra

I. Micro-SERVICES

Two. Api Gateway

Three. Use of Kong

I. Micro-SERVICES

For some traditional large-scale projects, the traditional way will have some defects, such as new familiarity with the system cost is high (because the whole system as a whole, each other will have a certain involvement), the project

Long time, refactoring difficulties (the introduction of a new technology may require the entire project to be pushed back), not easy to replace the new technology, and the whole project will slowly become a Big Mac.

So there is the concept of microservices, a service that implements a different feature or function. Every single micro-service is a small application. Some microservices may expose some APIs to

Other micro-services or customers. such as 1 (splitting of the various businesses):

Figure 1

For microservices, there are applications like Netflix, Amazon, ebay and so on.

Of course, MicroServices also have some drawbacks, such as how to maintain database transactions if each service (per application) has a database. Another example is that calls between services can be

can become unreachable due to network reasons, additional code is added to the code that fails the request.

Two. Api Gateway

API Gateway is the API gateways. All requests go through this gateway first. This is somewhat similar to the front-end controller mode and is somewhat similar to the facade mode. As shown in 2:

Figure 2

Since all requests go through this API gateway, You can do permissions control, security, load balancing, request distribution, monitoring , and so on.

So, why use this API gateway this thing, the main reason is that a customer can directly request each service. Each of these services has a URL. These URLs and loads are

Device mapping. In order to get product information, customers need to send a lot of request requests . This is not very good. Another problem is that possible protocols are different , not necessarily HTTP, such as possible

Other protocols may be required due to firewall or any limitations. In addition, later refactoring may be split interface, or merge interface , because the client and the API to deal with directly, so

More difficult.

So, as shown in Figure 1, the API gateway can be turned into the following 3:

Figure 3

Of course, any technology is flawed, as is API Gateway, which can be a performance bottleneck, for example.

Three. Use of Kong

Kong is a ready-made API Gateway solution that has been developed on Nginx.

API Gateway can be implemented in many ways, such as using a NIO-based framework such as Netty,vertx,spring Reactor,joss undertow on the JVM. Now a comparison process that is not based on the JVM is NodeJs. The others are Nginx Plus.

The use of Kong is described below.

    • 3.1 Installing Kong

    • 3.2 Adding APIs

3.1 Installing Kong

Reference: Https://getkong.org/install/, it is written in more detail, but to pre-install a Cassandra database (Introduction: http://cassandra.apache.org/). After installation, theKong project will monitor two ports, one 8000 and one 8001. The 8000 port is accessible to the user, that is, the user sends the request to port 8000 of the Kong project first, and then

The post-Kong project helps you move to your backend app API. The 8001 port is the management port, for example, the administrator can get the API you have added via 8001 ports.

3.2 Adding APIs

Reference Document: https://getkong.org/docs/0.5.x/admin-api/, which describes the management of the API, including additions and deletions to check and change. Here are some things I don't know about the first time I use it:

3.2.1 Lists the APIs that have been added

[HTML]View PlainCopy
    1. Curl localhost:8001/apis/

3.2.2 Join API

Single join:

[HTML]View PlainCopy
    1. Curl-i-x POST--url http://localhost:8001/apis/--data 'upstream_url=http://camp.uats.cc '--data 'request _path=Login '

The above-mentioned command says:

    • --url:http://localhost:8001/apis/fixed, join the API will have to write this, expressed to Kong management.

    • Upstream_url: Represents our website. Equivalent to a request prefix.

    • Request_path: That's exactly our API.

Deploy all the APIs with Request_host:

[HTML]View PlainCopy
    1. Curl-i-x POST--url http://localhost:8001/apis/--data 'upstream_url=http://183.131.76.124:4100/'--data 'request_host=183.131.76.122 '

3.2.3 Delete API

[HTML]View PlainCopy
    1. Curl-i-X DELETE LOCALHOST:8001/APIS/00F90CA9-CF2D-4830-C842-3B90F6CD08AF
The following string represents the ID of the API being added.

Four. Reference:

1. API Gateway mode: http://microservices.io/patterns/apigateway.html

2. nginx:https://www.nginx.com/blog/introduction-to-microservices/

3. Kong Project website: https://getkong.org/


Ext.: http://blog.csdn.net/pzxwhc/article/details/49873623

Micro Services, Apigateway and Kong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.