Git Product home page Git Product logo

kuqirpc's Introduction

KuqiRPC

轻量级 RPC Framework

cartoon

Framework Architecture

  • 透明化远程服务调用:代理模式
  • 消息编码和解码:序列化
  • 通信:单线程 + epoll多路复用

消息里会有携带RequestID,来实现异步返回Future

arch

整体架构图

arch
网络通信时序图

Data Structure

UML

UML

Tutorial

Server KV test

#include "../src/network/eventloop.h"
#include "../src/rpc/rpc_server.h"
#include "../src/kvtest/db.h"

int main() {
    Network::EventLoop looper;
    RPC::RpcServer serv(&looper, 8080);
    serv.Start();

    KuqiKV::DB db;
    serv.reg("DB::Put", &db, &KuqiKV::DB::Put);
    serv.reg("DB::Get", &db, &KuqiKV::DB::Get);

    looper.loop();

    return 0;
}

Client KV test

#include <thread>
#include <iostream>
#include "../src/rpc/future.h"
#include "../src/network/client.h"
#include "../src/rpc/rpc_client.h"
#include "../src/kvtest/kv_protocol.h"

int main() {
    Network::EventLoop looper;
    RPC::RpcClient client(&looper);

    Network::Client::EndPoint endPoint{"127.0.0.1", 8080};
    client.connect(endPoint);

//    另外开启一个线程运行loop
    std::thread t1([&](){
        looper.loop();
    });

    KV_Protocol::PutArgs putArgs{"test_key", "rpc msg"};
    Future<KV_Protocol::PutReply> putFu;
    client.Call("DB::Put", &putArgs, &putFu);

    putFu.Wait();
    std::cout << (int)putFu.Get().ok << std::endl;


    KV_Protocol::GetArgs getArgs{"test_key"};
    Future<KV_Protocol::GetReply> GetFu;
    client.Call("DB::Get", &getArgs, &GetFu);
    GetFu.Wait();
    std::cout << (int)GetFu.Get().ok << " " << GetFu.Get().value << std::endl;

    t1.join();

    return 0;
}

Others

reflect demo

double free

epool ET|LT模式

循环include -> 前置声明

类内static成员初始化

头文件中函数实现只能inline

不要在头文件定义static

模板的声明和实现必须写在一起

kuqirpc's People

Contributors

v4if avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  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.