krakend 试用
基于社区版本运行,可以自己构建
构建
或者使用使用官方的二进制文件
git clone https://github.com/devopsfaith/krakend-ce.git
make build
试用
- 配置
主要测试一个插件的使用以及数据编码&&数据过滤,同时包含了cache
{
"version": 2,
"name": "My lovely gateway",
"port": 8080,
"timeout": "5s",
"endpoints": [
{
"endpoint": "/myrss/{user}",
"backend": [
{
"group": "mydemo",
"url_pattern": "/users/{user}",
"host": [
"https://jsonplaceholder.typicode.com"
]
},
{
"host": [
"http://feed.cnblogs.com"
],
"url_pattern": "/blog/u/161986/rss/",
"encoding": "rss",
"group": "dalongrong",
"whitelist": [
"items",
"title"
],
"extra_config": {
"github.com/devopsfaith/krakend-ratelimit/juju/proxy": {
"maxRate": 1,
"capacity": 1
},
"github.com/devopsfaith/krakend-circuitbreaker/gobreaker": {
"interval": 60,
"timeout": 10,
"maxErrors": 1
}
}
}
]
},
{
"endpoint": "/demoapp",
"backend": [
{
"url_pattern": "/users",
"is_collection": true,
"host": [
"https://jsonplaceholder.typicode.com"
],
"extra_config": {
"github.com/devopsfaith/krakend-httpcache": {}
},
"mapping": {
"collection": "myusers"
}
}
]
},
{
"endpoint": "/myrss",
"backend": [
{
"host": [
"http://feed.cnblogs.com"
],
"url_pattern": "/blog/u/161986/rss/",
"encoding": "rss",
"group": "dalongrong",
"whitelist": [
"items",
"title"
],
"extra_config": {
"github.com/devopsfaith/krakend-ratelimit/juju/proxy": {
"maxRate": 1,
"capacity": 1
},
"github.com/devopsfaith/krakend-circuitbreaker/gobreaker": {
"interval": 60,
"timeout": 10,
"maxErrors": 1
}
}
}
]
}
]
}
- 说明
/myrss/1 是一个api 聚合的测试,聚合了博客园rss 数据以及一个公用rest api 数据,/demoapp 主要是集成了cache 插件,同时处理的是集合
说明
以上的测试比较简单,没有多少复杂的东西,我们可以集合自己的场景学习下,但是krakend对于api 中的问题,也不是100%都能解决的,只是
krakend解决api 的方式很不错
参考资料
https://www.krakend.io/docs/backends/caching/
https://www.krakend.io/docs/backends/overview/