Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xcfyl/drpc
基于netty的轻量级rpc框架
https://github.com/xcfyl/drpc
netty rpc-framework zookeeper
Last synced: about 1 month ago
JSON representation
基于netty的轻量级rpc框架
- Host: GitHub
- URL: https://github.com/xcfyl/drpc
- Owner: xcfyl
- Created: 2023-06-21T15:56:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-18T14:39:05.000Z (over 1 year ago)
- Last Synced: 2024-10-21T06:10:56.750Z (3 months ago)
- Topics: netty, rpc-framework, zookeeper
- Language: Java
- Homepage: https://github.com/xcfyl/drpc
- Size: 489 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[TOC]
# 一、README.md
+ [English](README_EN.md)
# 二、简介
该项目是采用模块化设计思路构建的简易rpc系统,适合rpc原理学习,掌握基本的rpc概念。主要包含如下内容:
1. 基于netty的rpc通信协议格式
2. 基于zookeeper的注册中心实现
3. 基于jdk的动态代理
4. 基于jdk和fastjson的序列化
5. 基于观察者模式的事件发布机制
6. 基于责任链模式的rpc客户端和服务端过滤器
7. rpc路由层设计和实现,主要包括随机路由策略和轮询路由策略
8. 和springboot的简易整合,支持简单的注解开发# 三、基本上使用
## 3.1 引入maven依赖
```xml
com.github.xcfyl.drpc
drpc-spring-boot-starter
1.1-SNAPSHOT```
## 3.2 api定义
```java
@DrpcReference
public interface ReplyService {
String reply(String message);
}
```## 3.3 api实现定义
```java
@DrpcService
public class ReplyServiceImpl implements ReplyService {
@Override
public String reply(String message) {
return message;
}
}
```## 3.4 启用drpc
### 3.4.1 服务提供者
1. 服务提供者启用
```java
@EnableDrpcServer(scanPackages = "com.github.xcfyl.drpc")
@SpringBootApplication
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
```2. 服务提供者的配置文件
``` properties
server.port=17001
server.request.limit=1024
server.registry.type=zookeeper
server.registry.addr=127.0.0.1:2181
server.application.name=app2
server.serializer=jdk
```### 3.4.2 服务消费者
1. 服务消费者启用
```java
@EnableDrpcClient(scanPackages = "com.github.xcfyl.drpc")
@SpringBootApplication
public class ConsumerApplication {
public static void main(String[] args) throws Throwable {
SpringApplication.run(ConsumerApplication.class, args);
}
}
```2. 服务消费者的配置文件
```properties
client.request.timeout=3000
client.proxy=jdk
client.router=roundrobin
client.request.limit=2048
client.registry.type=zookeeper
client.registry.addr=127.0.0.1:2181
client.application.name=client1
client.serializer=jdk
client.subscribe.retry.times=3
client.subscribe.retry.interval=1000
client.request.retry.times=1
client.request.retry.interval=3000
client.reconnect.times=3
client.reconnect.interval=1000
```### 3.4.3 controller
```java
@RestController
@ResponseBody
public class ReplyController {
@Resource
private ReplyService replyService;@GetMapping("/reply")
public String reply(@RequestParam("msg") String message) {
return replyService.reply(message);
}
}
```