# incubator-shenyu
**Repository Path**: anykn/incubator-shenyu
## Basic Information
- **Project Name**: incubator-shenyu
- **Description**: JAVA语言中高性能,可插拔,响应式API网关
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://dromara.org
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1012
- **Created**: 2022-03-15
- **Last Updated**: 2022-03-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
应用于所有微服务场景的,可扩展、高性能、响应式的 API 网关解决方案
https://shenyu.apache.org/
English | 简体中文
--------------------------------------------------------------------------------
# 架构

--------------------------------------------------------------------------------
# 为什么叫ShenYu
ShenYu (神禹)是我们古代君王夏禹的尊称(后世也尊称大禹),为造福百姓,成功治理黄河水患,留下了三过家门而不入的感人故事。其和尧舜并称为中国古代最伟大的三位君王。
* 首先,取名为ShenYu是弘扬我们中华文明的传统美德。
* 其次,网关最最重要的是对流量的治理。
* 最后,社区将会以公平,公正,公开,任人唯贤的做事方式,致敬神禹的同时也符合Apache Way。
--------------------------------------------------------------------------------
# 功能特点
* 提供了诸如限流、熔断、转发 、重写、重定向、和路由监控等插件;
* 支持 HTTP、RESTFul、WebSocket、Dubbo、 GRPC、 Tars、 Spring Cloud 代理;
* 支持热插拔,用户可以定制化开发;
* 为了灵活的适配,选择器和规则可以动态的适配;
* 支持集群部署;
* 支持 A/B 测试和灰度发布。
--------------------------------------------------------------------------------
# 快速体验
### 启动Apache ShenYu Admin
```
> docker pull apache/shenyu-admin
> docker network create shenyu
```
* 使用 `h2` 来存储后台数据:
```
> docker run -d -p 9095:9095 --net shenyu apache/shenyu-admin
```
### 启动Apache ShenYu Bootstrap
```
> docker network create shenyu
> docker pull apache/shenyu-bootstrap
> docker run -d -p 9195:9195 --net shenyu apache/shenyu-bootstrap
```
### 设置路由规则
* 如果你有一个这样的接口 :http://127.0.0.1:8080/helloworld,它的直接访问返回如下
```json
{
"name" : "Shenyu",
"data" : "hello world"
}
```
* 单机模式设置路由规则
Headers 中添加 `localKey: 123456`。如果需要自定义 localKey,可以使用 sha512 工具根据明文生成 key,并更新 `shenyu.local.sha512Key` 属性。
```
curl --location --request POST 'http://localhost:9195/shenyu/plugin/selectorAndRules' \
--header 'Content-Type: application/json' \
--header 'localKey: 123456' \
--data-raw '{
"pluginName": "divide",
"selectorHandler": "[{\"upstreamUrl\":\"127.0.0.1:8080\"}]",
"conditionDataList": [{
"paramType": "uri",
"operator": "match",
"paramValue": "/**"
}],
"ruleDataList": [{
"ruleHandler": "{\"loadBalance\":\"random\"}",
"conditionDataList": [{
"paramType": "uri",
"operator": "match",
"paramValue": "/**"
}]
}]
}'
```
* 通过网关代理请求:http://localhost:9195/helloworld 请求服务,返回如下:
```json
{
"name" : "Shenyu",
"data" : "hello world"
}
```
--------------------------------------------------------------------------------
# 插件
无论请求何时进入,ShenYu 会通过响应链执行所有已打开的插件。
插件是 ShenYu 的灵魂,并且插件也是可扩展和热插拔的。
不同的插件实现不同的功能。
当然,用户也可以定制化插件去满足他们自己的需求。
如果你有定制化插件的需求,请参看这里:[custom-plugin](https://shenyu.apache.org/zh/docs/developer/custom-plugin)
--------------------------------------------------------------------------------
# 选择器和规则
选择器和规则会根据 HTTP 的请求头来路由你的请求。
选择器是你的第一个路由,它是粗粒度的,举个例子,模块级别。
规则是你的第二个路由,即你认为你的请求应该做什么,举个例子,模块中的方法级别。
选择器和规则只匹配一次,然后返回匹配。因此,最粗粒度应排在最后。
--------------------------------------------------------------------------------
# 数据缓存 & 数据同步
所有的数据都被缓存在 JVM 的 ConcurrentHashMap 中,所以它非常快。
当用户在后台界面改变配置信息时,ShenYu 通过监听 ZooKeeper node,WebSocket push,HTTP longPull 来动态更新缓存。


--------------------------------------------------------------------------------
# 必要条件
* JDK 1.8+
--------------------------------------------------------------------------------
# 文档 & 网站
[](https://shenyu.apache.org/docs/index)
[](https://shenyu.apache.org/zh/docs/index/)
--------------------------------------------------------------------------------
# Github stars趋势
[](https://starchart.cc/apache/incubator-shenyu.svg)
--------------------------------------------------------------------------------
# 目前已知用户
为了便于登记,欢迎已经使用了 ShenYu 的公司在 [https://github.com/apache/shenyu/issues/68](https://github.com/apache/shenyu/issues/68) 注册。(仅适用于开源用户)
所有用户 : [Known Users](https://shenyu.apache.org/zh/community/user-registration/)