apache / apache/brpc

brpc 访问etcd的restful接口的问题

Open
#1,775 13 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

我想尝试用brpc来访问etcd的kv服务,实现了一个put key value的功能,demo代码如下,功能是正常的,但是我想用brpc实现watch功能,就出现问题了。
```
void PutKeyValue(brpc::Channel& channel) {
brpc::Controller cntl;
brpc::URI& uri = cntl.http_request().uri();
uri.set_path("/v3/kv/put");
cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
butil::IOBufBuilder os;
os << "{\"key\":\"Zm9v\",\"value\":\"YmFy\"}";
os.move_to(cntl.request_attachment());

channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
if (cntl.Failed()) {
std::cerr << cntl.ErrorText() << std::endl;
return;
}
std::cout << cntl.response_attachment() << std::endl;
}
```
watch的demo代码如下, 调用CallMethod后,就一直阻塞在这个调用这里了。 这个watch机制应该是http的 chunked mode, 不知道brpc client应该如何处理这种chunked mode?

```
void Watch(brpc::Channel& channel) {
brpc::Controller cntl;
cntl.http_request().uri().set_path("/v3/watch");
cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
butil::IOBufBuilder os;
os << "{\"create_request\": {\"key\":\"Zm9v\"}}";
os.move_to(cntl.request_attachment());

channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
if (cntl.Failed()) {
std::cerr << cntl.ErrorText() << std::endl;
return;
}
std::cout << cntl.response_attachment() << std::endl;
while (1) {sleep(1111111);}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the brpc::Channel and brpc::Controller usage shown for /v3/kv/put and /v3/watch, then inspect how CallMethod handles the HTTP response attachment. Reproduce the /v3/watch request against etcd and determine how its chunked response should be consumed; done means the watch request can receive streamed events without blocking indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.