Gravitee.io api gateway 试用
Posted rongfengliang-荣锋亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gravitee.io api gateway 试用相关的知识,希望对你有一定的参考价值。
以前写过几篇关于整体介绍的以及 使用docker 运行的简单说明,有了docker-compose 环境我们可以
方便的进行测试使用了。
环境准备
- docker-compose 文件
version: \'3\'
networks:
default:
services:
image: nginx:1.15-alpine
container_name: gio_platform_nginx
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/ssl/gio-selfsigned.crt:/etc/ssl/certs/gio-selfsigned.crt
- ./nginx/ssl/gio-selfsigned.key:/etc/ssl/private/gio-selfsigned.key
- ./nginx/ssl/gio.pem:/etc/ssl/certs/gio.pem
ports:
- "80:80"
- "443:443"
depends_on:
- apim_gateway
- apim_portal
- apim_management
- am_gateway
- am_management
- am_webui
mongodb:
image: mongo:3.4
container_name: gio_platform_mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_DATABASE=gravitee
volumes:
- ./mongo/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./data/mongo:/data/db
- ./logs/mongodb:/var/log/mongodb
elasticsearch:
image: elasticsearch:6.4.0
container_name: gio_platform_elasticsearch
ports:
- 9200:9200
environment:
- http.host=0.0.0.0
- transport.host=0.0.0.0
- xpack.security.enabled=false
- xpack.monitoring.enabled=false
- cluster.name=elasticsearch
ulimits:
nofile: 65536
volumes:
- ./data/elasticsearch:/usr/share/elasticsearch/data
- ./logs/elasticsearch:/var/log/elasticsearch
apim_gateway:
image: graviteeio/gateway:latest
container_name: gio_platform_apim_gateway
volumes:
- ./logs/apim-gateway:/opt/graviteeio-gateway/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://elasticsearch:9200
depends_on:
- mongodb
- elasticsearch
apim_portal:
image: graviteeio/management-ui:latest
container_name: gio_platform_apim_portal
environment:
- MGMT_API_URL=https:\\/\\/localhost\\/apim\\/management\\/
depends_on:
- apim_management
apim_management:
image: graviteeio/management-api:latest
container_name: gio_platform_apim_mgmt_api
volumes:
- ./logs/apim-management-api:/opt/graviteeio-management-api/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://elasticsearch:9200
- gravitee_jwt_cookiepath=/apim/management
- gravitee_jwt_cookiesecure=true
depends_on:
- mongodb
- elasticsearch
am_gateway:
image: graviteeio/am-gateway:2
container_name: gio_platform_am_gateway
volumes:
- ./logs/am-gateway:/opt/graviteeio-am-gateway/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
depends_on:
- mongodb
am_management:
image: graviteeio/am-management-api:2
container_name: gio_platform_am_management
volumes:
- ./logs/am-management-api:/opt/graviteeio-am-management-api/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_jwt_cookiepath=/am/management
- gravitee_jwt_cookiesecure=true
depends_on:
- mongodb
am_webui:
image: graviteeio/am-management-ui:2
container_name: gio_platform_am_webui
environment:
- MGMT_API_URL=https:\\/\\/localhost\\/am\\/
- MGMT_UI_URL=https:\\/\\/localhost\\/am\\/ui\\/
volumes:
- ./logs/am-webui:/var/log/nginx
depends_on:
- am_management
- 说明
使用了官方的demo,稍有修改,比如es 的版本以及对于nginx 的配置(虚拟主机),具体
修改之后的项目参考https://github.com/rongfengliang/gravitee-docker-compose
运行
很简单,启动即可,如果是clone 的github 代码仓库,如下操作
cd platform && docker-compose up -d
试用
配置参考的官方demo,同时操作基本使用的都是UI,主要是比较方便。
api 管理界面是https://localhost/apim/portal 账户 admin admin
-
创建api
进入管理中心
添加 api 入口
基本信息填写
配置后端api
添加api 计划 (api 计划对于我们的api 生命周期管理比较重要)
添加api docs (略过),实际生产中这个也是一个很重要的,需要写好
发布&&启动api
效果
api 库的界面 -
创建app并进行api 订阅操作
因为我们的api 是给予token 的请求模型,需要进行订阅,对于开放的我们可以直接进行操作
添加app入口
app 简单配置
订阅api,会有一个审批的处理过程 - api 管理者审批订阅
- 请求调用api
请求格式
curl -H "X-Gravitee-Api-Key: <your-api-key>" \\
https://GATEWAY_SERVER_DOMAIN/apim/<contexpath>
测试
curl -ki -H "X-Gravitee-Api-Key: 47805115-e6b6-4e50-a17b-d30657774734" \\
https://localhost/apim/demo
HTTP/1.1 200 OK
Server: nginx/1.15.8
Date: Tue, 01 Jan 2019 00:30:34 GMT
Content-Type: application/json
Content-Length: 483
Connection: keep-alive
X-Gravitee-Transaction-Id: 1766e8b7-3e82-4b87-a6e8-b73e824b877a
{
"headers" : {
"Host" : "api.gravitee.io",
"User-Agent" : "curl/7.54.0",
"Accept" : "*/*",
"Accept-Encoding" : "deflate, gzip",
"X-Forwarded-For" : "172.19.0.1, 111.40.219.127",
"X-Forwarded-Host" : "localhost",
"X-Forwarded-Port" : "443",
"X-Forwarded-Proto" : "https",
"X-Forwarded-Server" : "efa2d0b84593",
"X-Gravitee-Transaction-Id" : "1766e8b7-3e82-4b87-a6e8-b73e824b877a",
"X-Real-Ip" : "172.19.0.1"
},
"query_params" : { }
}%
- 请求统计界面
说明
Gravitee.io 对于api 的管理还是很方便的,同时包含了比较完整的生命的处理,使用起来比较便捷
参考资料
https://github.com/rongfengliang/gravitee-docker-compose
https://docs.gravitee.io/apim_quickstart_publish.html
https://docs.gravitee.io/apim_quickstart_consume.html
以上是关于Gravitee.io api gateway 试用的主要内容,如果未能解决你的问题,请参考以下文章
0601-Zuul构建API Gateway-API gateway简介
如果在 Terraform 模块中创建了 aws_api_gateway_integration,如何在 aws_api_gateway_deployment 资源上填充depends_on?
api-gateway实践(14)新服务网关 - 业务场景验证api-gateway-engine携带有效token访问SvcApp (未完!!!!!!!!!!)