yq33victor opened a new issue, #2951:
URL: https://github.com/apache/brpc/issues/2951

   hi 
,我目前想用brpc做一些http相关的工作,基本的逻辑是client发送request给server,server那边会在一段时间内产生多个responses,所以client应该要持续的流式接收这些responses。目前我的client只能接收到最终的batch在一起resps,而不是每次streaming的收到返回值。帮忙看下这一块是否有解决办法呢,感谢🙏.
   
   目前server的写resp的逻辑大概如下:
   ```
   class ServerStreamData{
    public:
     ServerStreamData(brpc::Controller* controller,
                                     ::google::protobuf::Closure* done)
         : controller_(controller),
           done_(done) {
       pa_ = controller_->CreateProgressiveAttachment();
   
       controller_->http_response().set_content_type("text/event-stream");
       controller_->http_response().set_status_code(200);
       controller_->http_response().SetHeader("Connection", "keep-alive");
       controller_->http_response().SetHeader("Cache-Control", "no-cache");
     
       // stream模式下,先将done执行
       done_->Run();
    }
   
    // server每次产生一个data就会调用一次这个write函数
    // 直到结束
    //
    bool write(const std::string& attachment) {
      io_buf_.clear();
      io_buf_.append(attachment);
      pa_->Write(io_buf_);
   
      return true;  
    }
   
    private:
     brpc::Controller* controller_;
     ::google::protobuf::Closure* done_;
     butil::intrusive_ptr<brpc::ProgressiveAttachment> pa_;
     butil::IOBuf io_buf_;
   };
   ```
   
   client目前的逻辑如下:
   ```
   brpc::Controller cntl;
   cntl.http_request().uri() = target_uri;
   cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
   cntl.request_attachment().append(request);
   
   // Because `done'(last parameter) is NULL, this function waits until
   // the response comes back or error occurs(including timeout).
   channel_ptr->CallMethod(NULL, &cntl, NULL, NULL, NULL);
   if (cntl.Failed()) {
     LOG(ERROR) << "Call method error: " << cntl.ErrorText();
     return;
   }
   
   LOG(INFO) << "get response: " << cntl.response_attachment().to_string();
   ```
   
   我看了下rpc模式下有支持streaming client的方法,不知道在http下面怎么解决呢,谢谢。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to