Git Product home page Git Product logo

Comments (15)

holmes1412 avatar holmes1412 commented on May 23, 2024

小伙伴好呀,整体思路没有什么问题,如果想用压缩功能,你相当于要把server准备发出的内容做压缩、client接收到的每块内容做解压、然后server该怎么拆和client该怎么拼接都是你的逻辑~

1、如何利用srpc的压缩?

srpc在框架层已经帮你做好压缩/解压了,如果server和client双方都是SRPC的框架编译出来的,那么只需要server加上一行就可以进行压缩、而client会自动解压,你无需再做任何事情。

我们用tutorial-01/tutorial-02为例子:

tutorial-01的实现里加一行就行:

class ExampleServiceImpl : public Example::Service                              
{                                                                               
public:                                                                         
    void Echo(EchoRequest *req, EchoResponse *resp, RPCContext *ctx) override   
    {                                                                           
        resp->set_message("Hi back");                                           
        ctx->set_compress_type(RPCCompressGzip); // 这里以Gzip为例子,srpc还支持其他压缩类型
        printf("Server Echo()\nget_req:\n%s\nset_resp:\n%s\n",                  
                req->DebugString().c_str(), resp->DebugString().c_str());          
    }                                                                           
};

然后make && make tutorial,使用srpc_pb_server和srpc_pb_client跑起来就可以互通,而期间的数据是被压缩过的。

2、RPC和原先想要用的HTTP有什么区别?

你要基于srpc框架开发,所以会涉及IDL文件中的请求和回复格式,这个你可以参考./tutorial/echo_pb.proto,server就是实现这个Echo函数,client就是请求这个Echo函数。srpc框架可以发出HTTP请求,还是用tutorial01/tutorial02为例子,只需要把SRPCServer改成SRPCHttpServer、SRPCClient改成SRPCHttpClient,就可以跑起来了。

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

非常感谢您百忙之中给我回复问题,实际的情况是这样的:
服务端是部署的简单对象存储(其他组的服务,我只能进行http请求文件压缩传输,比如gzip,然后客户端收到响应进行解压缩后存储),不知道这样的情况下还能用到咱们srpc中的压缩功能吗

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

尊敬的作者大大,我看到了chanchan基于workflow写的wfrest里有个gzip压缩/解压缩的功能,我想可以先参考他的实现方法去做我说的事

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

你好。感觉这个问题,和rpc没有关系。用workflow发一个gzip压缩请求不就好了?收到回复也解压一下。感觉这个完全可以框架之外做。
另外,可以参考一下基于workflow的wfrest项目:https://github.com/wfrest/wfrest
wfrest是有处理压缩的,但主要做server。

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

wfrest里有个例子,使用workflow发gzip压缩的http请求,你可以看一下:
https://github.com/wfrest/wfrest/blob/main/docs/cn/compress.md

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

wfrest里有个例子,使用workflow发gzip压缩的http请求,你可以看一下: https://github.com/wfrest/wfrest/blob/main/docs/cn/compress.md

非常感谢您的回复,我当时就是看到srpc支持很多种压缩方式,所以才突发奇想有了这个issue,再次感谢您的帮助!

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

不客气的。你看看能不能解决你的需求。有任何别的问题随时沟通。

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

我发现在我回复之前,你已经找到了wfrest了😄

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

我发现在我回复之前,你已经找到了wfrest了😄

非常感谢您和22姐大晚上回复我!
workflow是个非常优秀的框架,借助它,让我这个小白能快速实现我想做的功能,后面我会努力学习其中的设计**!

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

哈哈哈。感谢使用。给workflow点个star再走哈。

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

必须的,全都点了一遍!

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

之前说的那个功能我已经实现了,速度还挺快,这个issue我就关啦

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

之前说的那个功能我已经实现了,速度还挺快,这个issue我就关啦

嗯嗯,能解决问题就太好了!你好像忘了star workflow项目😂。

from srpc.

AndrewAndHelen avatar AndrewAndHelen commented on May 23, 2024

之前说的那个功能我已经实现了,速度还挺快,这个issue我就关啦

嗯嗯,能解决问题就太好了!你好像忘了star workflow项目😂。

尴尬了啊,这回我点了。。。 😄

from srpc.

Barenboim avatar Barenboim commented on May 23, 2024

之前说的那个功能我已经实现了,速度还挺快,这个issue我就关啦

嗯嗯,能解决问题就太好了!你好像忘了star workflow项目😂。

尴尬了啊,这回我点了。。。 😄

使用愉快哈。有问题随时发issue!

from srpc.

Related Issues (20)

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.