# 远程服务调用 **Repository Path**: sdliang/stone-rpc ## Basic Information - **Project Name**: 远程服务调用 - **Description**: 远程服务调用 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-12-20 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 远程服务调用 #### 介绍 远程服务调用框架. 在已有服务架构上, 将现有服务整合成分布式服务. 保持现有服务架构, 采用非侵入的方式. #### 软件架构 服务调用采用: feign + ribbon 服务注册和发现采用: zookeeper 服务安全控制: 默认采用参数签名的方式, 密钥保存在数据库 #### 待完善 客户端服务注入: 采用spring注入机制,自动注入feign定义的接口 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. server pom.xml 引入: ```xml net.stone.rpc stone-rpc-server 0.0.1-SNAPSHOT ``` 系统配置文件: ```yaml stone: rpc: register: config-center: 注册中心地址(127.0.0.1:2181) server: name: 服务名称 address: 服务地址(ip:port) security: type: 安全控制方式(none/sign, 或者自定义,实现SecurityValidator接口) ``` 设置服务端注解: ```java @EnableRpcServer(interceptor = InterceptorType.JAX_WS) ``` 需要安全控制的接口加上注解: @RpcSecurity 2. client pom.xml 引入: ```xml net.stone.rpc stone-rpc-client 0.0.1-SNAPSHOT ``` 系统配置文件: ```yaml stone: rpc: register: config-center: 127.0.0.1:2181 security: app-id: 客户端ID app-secret: 客户端密钥(为空时,从数据库获取) ``` 设置客户端注解: ```java @EnableRpcClient(type = RpcClientType.FEIGN) ``` 编写接口类: ```java @FeignClient(address = "服务名称", security = RpcSecurityProperties.TYPE_SIGN, balance = true) @Produces("application/json;charset=utf-8") public interface ShopGiftResource { @GET @Path("/test") Response list(@QueryParam("type") Integer type, @QueryParam("name") String name); } ``` 在调用的地方, 引入: ```java @Autowired(required = false) private RpcClient rpcClient; private void test() { ShopGiftResource shopGiftResource = rpcClient.get(ShopGiftResource.class); Response response = shopGiftResource.list(1, "test"); Assert.assertNotNull("查询结果为空", response.getRecordset()); response.getRecordset().forEach(shopGift -> System.out.println(shopGift.getName())); } ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)