代码拉取完成,页面将自动刷新
该RPC框架目前实现有
实现调用demo
public class RpcServerImplTest2 {
CountDownLatch countDownLatch = new CountDownLatch(1);
public static void main(String[] args) throws InterruptedException {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.codec("protostuff")
.timeout(5000)
// 设置服务注册为zookeeper, 支持zookeeper和nacos两个服务注册
.registry(new URL("zookeeper", "127.0.0.1", 2181))
.server("netty")
.port(20881)
.start();
// 注册
serverBootstrap.register(Demo.class, new DemoImpl());
System.out.println("启动成功");
}
}
public class RpcClientTest {
public static void main(String[] args) {
RpcClientConfiguration prop = new RpcClientConfiguration();
// 序列化,默认是protostuff
prop.setCodec("protostuff");
// 超时,默认是5000
prop.setTimeout(5000);
// 请求超时,默认是3000
prop.setRequestTimeout(3000);
// 设置客户端为netty, 默认是netty
prop.setProtocol("netty");
// 服务注册,目前支持 zookeeper和nacos两个, 默认是zookeeper
// 设置服务注册 , 为nacos
// URL nacosConf = new URL("nacos", "127.0.0.1", 8848);
// nacosConf = nacosConf.addParameter("namespace", "1ca3c65a-92a7-4a09-8de1-4bfe1c89d240");
// 设置服务注册 为zookeeper
prop.setRegistryUrl(new URL("zookeeper", "127.0.0.1", 2181));
// 注册器
// 远程 客户端
Demo proxy = RpcProxyFactory.create(Demo.class, prop, RpcProxyType.JDK_PROXY);
for (int i = 0; i < 20; i++) {
// 执行RPC请求
String res = proxy.sayHello();
System.out.println("rpc调用返回数据:" + res);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。