| 56 | }; |
| 57 | |
| 58 | int PressClient::init() { |
| 59 | brpc::ChannelOptions rpc_options; |
| 60 | rpc_options.connect_timeout_ms = _options->connect_timeout_ms; |
| 61 | rpc_options.timeout_ms = _options->timeout_ms; |
| 62 | rpc_options.max_retry = _options->max_retry; |
| 63 | rpc_options.protocol = _options->protocol; |
| 64 | rpc_options.connection_type = _options->connection_type; |
| 65 | if (_options->attachment_size > 0) { |
| 66 | _attachment.clear(); |
| 67 | _attachment.assign(_options->attachment_size, 'a'); |
| 68 | } |
| 69 | if (_rpc_client.Init(_options->host.c_str(), _options->lb_policy.c_str(), |
| 70 | &rpc_options) != 0){ |
| 71 | LOG(ERROR) << "Fail to initialize channel"; |
| 72 | return -1; |
| 73 | } |
| 74 | _method_descriptor = find_method_by_name( |
| 75 | _options->service, _options->method, _importer); |
| 76 | if (NULL == _method_descriptor) { |
| 77 | LOG(ERROR) << "Fail to find method=" << _options->service << '.' |
| 78 | << _options->method; |
| 79 | return -1; |
| 80 | } |
| 81 | _response_prototype = get_prototype_by_method_descriptor( |
| 82 | _method_descriptor, false, _factory); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | void PressClient::call_method(brpc::Controller* cntl, Message* request, |
| 87 | Message* response, Closure* done) { |