proxygen
RpcClient.cpp File Reference

Go to the source code of this file.

Classes

class  RpcPipelineFactory
 
class  BonkMultiplexClientDispatcher
 

Typedefs

using SerializePipeline = wangle::Pipeline< IOBufQueue &, Bonk >
 

Functions

 DEFINE_int32 (port, 8080,"test server port")
 
 DEFINE_string (host,"::1","test server address")
 
int main (int argc, char **argv)
 

Typedef Documentation

Definition at line 37 of file RpcClient.cpp.

Function Documentation

DEFINE_int32 ( port  ,
8080  ,
"test server port"   
)
DEFINE_string ( host  ,
"::1"  ,
"test server address"   
)
int main ( int  argc,
char **  argv 
)

For specific protocols, all the following code would be wrapped in a protocol-specific ServiceFactories.

TODO: examples of ServiceFactoryFilters, for connection pooling, etc.

Definition at line 98 of file RpcClient.cpp.

References wangle::ClientBootstrap< Pipeline >::connect(), folly::exceptionStr(), wangle::ClientBootstrap< Pipeline >::group(), folly::init(), and wangle::BaseClientBootstrap< Pipeline >::pipelineFactory().

98  {
99  folly::Init init(&argc, &argv);
100 
108  client.group(std::make_shared<folly::IOThreadPoolExecutor>(1));
109  client.pipelineFactory(std::make_shared<RpcPipelineFactory>());
110  auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get();
111  // A serial dispatcher would assert if we tried to send more than one
112  // request at a time
113  // SerialClientDispatcher<SerializePipeline, Bonk> service;
114  // Or we could use a pipelined dispatcher, but responses would always come
115  // back in order
116  // PipelinedClientDispatcher<SerializePipeline, Bonk> service;
117  auto dispatcher = std::make_shared<BonkMultiplexClientDispatcher>();
118  dispatcher->setPipeline(pipeline);
119 
120  // Set an idle timeout of 5s using a filter.
121  ExpiringFilter<Bonk, Xtruct> service(dispatcher, std::chrono::seconds(5));
122 
123  try {
124  while (true) {
125  std::cout << "Input string and int" << std::endl;
126 
127  Bonk request;
128  std::cin >> request.message;
129  std::cin >> request.type;
130  service(request).thenValue([request](Xtruct response) {
131  CHECK(request.type == response.i32_thing);
132  std::cout << response.string_thing << std::endl;
133  });
134  }
135  } catch (const std::exception& e) {
136  std::cout << exceptionStr(e) << std::endl;
137  }
138 
139  return 0;
140 }
fbstring exceptionStr(const std::exception &e)
folly::Future< Pipeline * > connect(const folly::SocketAddress &address, std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) override
void init()
char ** argv
BaseClientBootstrap< Pipeline > * pipelineFactory(std::shared_ptr< PipelineFactory< Pipeline >> factory) noexcept
ClientBootstrap * group(std::shared_ptr< folly::IOThreadPoolExecutor > group)