Skip to content

CasterWxBlog/Zeus

 
 

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进入过滤器管理界面。

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

系统内置路由:

Type Name Comment
pro DebugModeSetter 调试模式
pro DebugRequest 请求调试
pro HealthCheck 健康检查
pro TestRoute 路由选择
route ExecuteRoute 路由分发(核心)
post AddTimeStamp 添加时间戳
post DebugHeader 请求头调试
post DebugResponse 返回体调试
post SendResponse 返回体配置
post Stats 状态反馈
  • 测试路由状态

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 = "管理服务")
public class ZeusDemoApplication {
    public static void main(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")
public String hello() {
    return "Hello! " ;
}

Rpc远程调用

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

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

@RpcService
public class DoSomethingImpl implements DoSomething {

    private static List<String> users = new ArrayList<>();

    @Override
    public List<String> doHello() {
        users.add("user-1");
        users.add("user-2");
        users.add("user-3");
        return users;
    }
}

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

@RestController
public class HelloService {

    @RequestMapping(value = "/hello")
    public String hello() throws InterruptedException {
        RpcClient rpcClient = new RpcClient();
        rpcClient.doConnect("localhost", 18868); // port默认均为18868
        Object object = rpcClient.send(new RpcRequest("1", "com.antzuhl.zeusdemo2.service.impl.DoSomethingImpl", "doHello", null, null));

        return object.toString();
    }
}

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

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

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 71.9%
  • JavaScript 13.3%
  • Groovy 8.0%
  • HTML 5.1%
  • CSS 1.6%
  • TSQL 0.1%