RPC BASED ON NETTY Running in some business online.
当前采用简单的在消息体前加上4byte的消息长度值
// 需要先启动一个zookeeper作为服务注册发现中心
// 服务接口 public interface IHello { ` String say(String hello); int sum(int a, int b); int sum(Integer a, Integer b); } // 服务实现 public class HelloImpl implements IHello { public String say(String hello) { return "return " + hello; } public int sum(int a, int b) { return a + b; } public int sum(Integer a, Integer b) { return a + b * 3; } } // 客户端代码 // beanJavaConfig方式 @Bean public CountService countService() { RpcClientWithLB rpcClientWithLB = new RpcClientWithLB("fyes-counter"); rpcClientWithLB.setZkConn("127.0.0.1:2181"); rpcClientWithLB.init(); CountService countService = rpcClientWithLB.newProxy(CountService.class); return countService; } // 服务端发布 // xml配置方式 <bean class="com.github.liuzhengyang.simplerpc.ServerFactoryBean" init-method="start"> <property name="serviceInterface" value="com.test.liuzhengyang.CountService"/> <property name="port" value="8888"/> <property name="serviceName" value="fyes-counter"/> <property name="serviceImpl" ref="countServiceImpl"/> <property name="zkConn" value="127.0.0.1:2181"/>