# micro-rpc **Repository Path**: startgis/micro-rpc ## Basic Information - **Project Name**: micro-rpc - **Description**: 本项目为仿照dubbo开发的rpc框架。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: https://blog.csdn.net/Onthr - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2024-07-09 - **Last Updated**: 2024-07-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 如何开始 ## 1.准备 1.引入本项目到项目中,直接把源码包作为一个maven模块导入,然后在需要的地方引入该依赖即可。 ```xml org.example Micro-DUBBO 1.0-SNAPSHOT ``` 2.启动你的**redis**,同时记住Host 和 port ## 2.编写xml配置文件 **dubbo-application.xml** 注意名称要一致,不然将识别不出来!! 以下*号为必填项! ```Xml 服务的基本信息 * 服务名 * 服务主机 * 服务端口 权重,默认为1 注册中心配置连接 * 注册中心ip * 注册中心端口 注册中心数据库,默认为0 注册中心密码 你的最大连接数 注册服务提供 publicInterface.HelloService #服务接口全限定名 MicroRpc.provider.HelloServiceImpl ##服务实现全限定类名 publicInterface.HiService MicroRpc.provider.HiServiceImpl ...可有多个 注册你需要的服务引用 publicInterface.HiService #服务接口全限定名 ...可有多个 ``` ## 3.创建公共服务接口/ 服务提供者 / 服务消费者 **公共服务接口** ```java public interface HelloService { public String say(String msg); public Object hi(Integer msg); public User getUserById(Integer id); public boolean updateUser(User user); public void testvoid(); } ``` **服务提供者示例** ```java public class Provider1test { public static void main(String[] args) { AbstractApplicationContext context =new DefaultDubboApplicationContext(ProtocolTypes.DUBBO, LoadBalance.CONSISTENT_HASH); //第一个参数为协议,第二个参数为负载均衡策略 try { context.refresh(); System.out.println("刷新完毕 可以干点其他事"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } ``` **消费者示例代码** ```java public class ConsumerTest1 { public static void main(String[] args) { AbstractApplicationContext context= new DefaultDubboApplicationContext(ProtocolTypes.DUBBO, LoadBalance.RANDAM_WEIGHT); try { context.refresh(); System.out.println("刷新完毕"); HelloService helloService = context.getProtocol().getService(HelloService.class); for (int i = 0; i < 20; i++) { System.out.println("==============================="); System.out.println(helloService.say("markyao!!!")); System.out.println("==============================="); Thread.sleep(1000); } } catch (ClassNotFoundException | InterruptedException e) { e.printStackTrace(); } } } ``` # 注册中心管理页面 本项目是基于SpringBoot开发的一个简单管理系统。 想要开启该服务,直接引入本项目,然后开启Springboot启动类即可 =>**com.markyao.ApplicationRunner** 然后访问页面: http://localhost:6380/index