• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Zeus: 一行注解完成——服务发现,负载均衡,服务调用,API监控,配置中心,服务治理 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Zeus

开源软件地址:

https://gitee.com/CasterWx/Zeus

开源软件介绍:

Zeus

介绍

Zeus可以用于服务发现,服务治理,负载均衡,服务容错,服务调用,API网关,配置中心。

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

(项目更多功能正在开发中)

让我知道您正在使用Zeus。

服务注册

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

  • registryName :命名空间(集群管理)
  • zkAddr :zookeeper地址
  • serverName :服务名称
  • serverAddr :服务注册地址
@SpringBootApplication@ZeusRegistry(registryName = "user-center", zkAddr = "192.168.124.16:2181",        serverName = "server-1", serverAddr = "48.89.13.53:8080")public class ZeusDemoApplication {    public static void main(String[] args) {        SpringApplication.run(ZeusDemoApplication.class, args);    }}

服务发现

requestMethod : Get

获取所有集群名。

{  "code":200,  "message":"OK",  "data":[    "user-center2","user-center1","user-center3"  ]}

requestMethod : Get

获取指定集群下的所有服务节点信息。

response

{  "code":200,  "message":"OK",  "data":[{    "nameSpace":"user-center1",    "serverName":"server-1",    "data":"126",    "path":"/registry/user-center1/server-1"    }]  }

接口监控

为你的方法或是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方法来启动远程调用。

@RpcServicepublic 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来调用。

@RestControllerpublic 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,实例类,方法,参数类型列表,参数值列表。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap