Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持UNIX Domain socket吗? #268

Open
yongxiangzheng opened this issue Dec 7, 2022 · 8 comments
Open

支持UNIX Domain socket吗? #268

yongxiangzheng opened this issue Dec 7, 2022 · 8 comments

Comments

@yongxiangzheng
Copy link

请问 支持UNIX Domain socket方式的进程间通讯吗?

@Barenboim
Copy link
Contributor

支持。自定义协议的例子,tutorial-10里,就有uds的示例代码。

@Barenboim
Copy link
Contributor

噢噢,这是srpc项目啊。你想到workflow的项目里看一下。srpc的server端肯定是支持的,client我看看能不能配uds地址。

@Barenboim Barenboim reopened this Dec 7, 2022
@Barenboim
Copy link
Contributor

我看了一下,RPCClientParams好像不支持传入sockaddr:

struct RPCClientParams
{
	RPCTaskParams task_params;
//host + port + is_ssl
	std::string host;
	unsigned short port;
	bool is_ssl;
//or URL
	std::string url;
	std::string caller;
};

这个我们可以考虑加一下。不过,一般来讲,uds的话自定义协议是不是就可以了,没必要用带IDL的rpc?

@yongxiangzheng
Copy link
Author

嗯嗯,建议可以加下,我是认为使用自定义协议,那就得需要自己再封装socket,计划是找一个能有支持uds的rpc,这样可以减少一些代码维护和增加程序稳健性能

@Barenboim
Copy link
Contributor

自定义协议不用封装socket的。你看看一下这个文档和实例:
https://github.com/sogou/workflow/blob/master/docs/tutorial-10-user_defined_protocol.md
https://github.com/sogou/workflow/tree/master/tutorial/tutorial-10-user_defined_protocol
因为srpc其实就是基于workflow的一组自定义协议。自己写自定义协议,只需要写一下序列化和反序列化函数,你可以看看。
不过,srpc的client我们也加上sockaddr的支持吧。

@yongxiangzheng
Copy link
Author

好的,我看看,谢谢~

@Barenboim
Copy link
Contributor

Barenboim commented Apr 13, 2024

@yongxiangzheng
突然想起来,我们本来就支持Unix domain socket的srpc client。只需要利用一下workflow的upstream功能就可以了。添加一个upstream,让其包含一个server,地址是一个本地路径:

#include "workflow/UpstreamManager.h"

int main()
{
    UpstreamManager::upstream_create_round_robin("uds-host-name", false);
    UpstreamManager::upstream_add_server("uds-host-name", "/home/xxxxx/uds-service");

    struct RPCClientParams params = RPC_CLIENT_PARAMS_DEFAULT;
    params.host = "uds-host-name";
    Example::SRPCClient client(&params);
}

而server端直接用start(const struct sockaddr *addr, socklen_t addrlen);这个函数启动server,服务的地址在/home/xxxxx/uds-service就可以了。
非常抱歉一年多才想起来可以这么用。我们的http,redis这些协议的任务,也可以通过这个方式使用Unix domain socket。

@Barenboim
Copy link
Contributor

Workflow项目里关于upstream的文档:https://github.com/sogou/workflow/blob/master/docs/about-service-governance.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants