Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

41 Commits

Repository files navigation

Zeus

介绍

Zeus可以用于API网关,服务发现,服务调用,熔断限流,日志统计。

理念是用最简单的方式使用。

(该项目的另一种思路,实现最强大的后台代理,高可用的翻墙服务,https://github.com/CasterWx/Back-end-Broker)

API网关

运行部署zeus-gateway项目,访问http://api.zeus.com/zeus-gateway/admin/filterLoader.jsp进入过滤器管理界面。

分别添加需要的前置/后置过滤器。

系统内置路由:

TypeNameComment
proDebugModeSetter调试模式
proDebugRequest请求调试
proHealthCheck健康检查
proTestRoute路由选择
routeExecuteRoute路由分发(核心)
postAddTimeStamp添加时间戳
postDebugHeader请求头调试
postDebugResponse返回体调试
postSendResponse返回体配置
postStats状态反馈
  • 测试路由状态

http://api.zeus.com/zeus-gateway/api/{serviceName}/{serviceRequestPath}?params

服务注册

引入zeus-client模块,在启动类添加@ZeusRegistry标签即可。

  • serverName :服务名
  • serverAddr :注册中心地址
  • comment :服务描述
@SpringBootApplication@ZeusProperty(serverName = "domain", serverAddr = "127.0.0.1", comment = "管理服务")
publicclassZeusDemoApplication {
publicstaticvoidmain(String[] args) {
SpringApplication.run(ZeusDemoApplication.class, args);
}
}

服务发现

requestMethod : Get

获取所有集群名。

[
{
"id": 1,
"serviceName": "domain",
"serviceAddr": "127.0.0.1",
"port": 8888,
"living": 1,
"comment": "管理服务"
},
{
"id": 2,
"serviceName": "RpcDemo",
"serviceAddr": "127.0.0.1",
"port": 8881,
"living": 1,
"comment": "远程服务"
}
]

接口监控

为你的方法或是API添加@FlowMonitor(name)注释,你的该方法访问将会得到记录。

@RequestMapping(value = "/hello")
@FlowMonitor(name = "hello")
publicStringhello() {
return"Hello! " ;
}

Rpc远程调用

存在一个server-1,地址为localhost:8080,还存在一个server-2,地址为localhost:8090

server-1中有一个方法,假如它的作用是查询数据库返回用户信息,我们就可以给这个service类加上@RpcService方法来启动远程调用。

@RpcServicepublicclassDoSomethingImplimplementsDoSomething {
privatestaticList<String> users = newArrayList<>();
@OverridepublicList<String> doHello() {
users.add("user-1");
users.add("user-2");
users.add("user-3");
returnusers;
}
}

在server-2中如果我们想要调用server-1的doHello方法获取用户信息,就可以创建一个简单的RpcClient来调用。

@RestControllerpublicclassHelloService {
@RequestMapping(value = "/hello")
publicStringhello() throwsInterruptedException {
RpcClientrpcClient = newRpcClient();
rpcClient.doConnect("localhost", 18868); // port默认均为18868Objectobject = rpcClient.send(newRpcRequest("1", "com.antzuhl.zeusdemo2.service.impl.DoSomethingImpl", "doHello", null, null));
returnobject.toString();
}
}

此时访问这个/hello接口,可以得到返回的json结果。

{"code":0,"data":["user-1","user-2","user-3"],"requestId":"1"}

RpcRequest中参数为消息ID,实例类,方法,参数类型列表,参数值列表。

About

API网关中心,服务发现,服务调用,API监控,服务限流。

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages