[TOC]
This project is a simple rpc system built with modular design ideas, suitable for learning rpc principles and mastering basic rpc concepts. The main contents are as follows:
- rpc communication protocol format based on netty
- Zookeeper-based registry implementation
- Jdk-based dynamic proxy
- jdk and FastJSON-based serialization
- Event publishing mechanism based on observer pattern
- Chain of Responsibility based rpc client and server filters
- Design and implementation of rpc routing layer, including random routing strategy and polling routing strategy
- Easy integration with springboot for easy annotation development
<dependency>
<groupId>com.github.xcfyl.drpc</groupId>
<artifactId>drpc-spring-boot-starter</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
@DrpcReference
public interface ReplyService {
String reply(String message);
}
@DrpcService
public class ReplyServiceImpl implements ReplyService {
@Override
public String reply(String message) {
return message;
}
}
- Enabling Service Provider
@EnableDrpcServer(scanPackages = "com.github.xcfyl.drpc")
@SpringBootApplication
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
- The service provider configuration template
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
- Enabling Service Consumer
@SpringBootApplication
@EnableDrpcClient(scanPackages = "com.github.xcfyl.drpc")
public class ConsumerApplication {
public static void main(String[] args) throws Throwable {
SpringApplication.run(ConsumerApplication.class, args);
}
}
- The service consumer configuration template
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
@RestController
@ResponseBody
public class ReplyController {
@Resource
private ReplyService replyService;
@GetMapping("/reply")
public String reply(@RequestParam("msg") String message) {
return replyService.reply(message);
}
}