GithubHelp home page GithubHelp logo

drpc's Introduction

[TOC]

一、README.md

二、简介

该项目是采用模块化设计思路构建的简易rpc系统,适合rpc原理学习,掌握基本的rpc概念。主要包含如下内容:

  1. 基于netty的rpc通信协议格式
  2. 基于zookeeper的注册中心实现
  3. 基于jdk的动态代理
  4. 基于jdk和fastjson的序列化
  5. 基于观察者模式的事件发布机制
  6. 基于责任链模式的rpc客户端和服务端过滤器
  7. rpc路由层设计和实现,主要包括随机路由策略和轮询路由策略
  8. 和springboot的简易整合,支持简单的注解开发

三、基本上使用

3.1 引入maven依赖

<dependency>
    <groupId>com.github.xcfyl.drpc</groupId>
    <artifactId>drpc-spring-boot-starter</artifactId>
    <version>1.1-SNAPSHOT</version>
</dependency>

3.2 api定义

@DrpcReference
public interface ReplyService {
    String reply(String message);
}

3.3 api实现定义

@DrpcService
public class ReplyServiceImpl implements ReplyService {
    @Override
    public String reply(String message) {
        return message;
    }
}

3.4 启用drpc

3.4.1 服务提供者

  1. 服务提供者启用
@EnableDrpcServer(scanPackages = "com.github.xcfyl.drpc")
@SpringBootApplication
public class ProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }
}
  1. 服务提供者的配置文件
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. 服务消费者启用
@EnableDrpcClient(scanPackages = "com.github.xcfyl.drpc")
@SpringBootApplication
public class ConsumerApplication {
    public static void main(String[] args) throws Throwable {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}
  1. 服务消费者的配置文件
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

@RestController
@ResponseBody
public class ReplyController {
    @Resource
    private ReplyService replyService;

    @GetMapping("/reply")
    public String reply(@RequestParam("msg") String message) {
        return replyService.reply(message);
    }
}

drpc's People

Contributors

xcfyl avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.