blob: e6f1b20837089ecaff71e075bea8765eb0e8cedd [file] [log] [blame]
David Reiss9f3296b2010-08-31 16:58:41 +00001#include "zmq.hpp"
2#include "TZmqServer.h"
3#include "Storage.h"
4
cyy316723a2019-01-05 16:35:14 +08005using apache::thrift::std::shared_ptr;
David Reiss9f3296b2010-08-31 16:58:41 +00006using apache::thrift::TProcessor;
7using apache::thrift::server::TZmqServer;
8using apache::thrift::server::TZmqMultiServer;
9
10class StorageHandler : virtual public StorageIf {
11 public:
12 StorageHandler()
13 : value_(0)
14 {}
15
16 void incr(const int32_t amount) {
17 value_ += amount;
18 }
19
20 int32_t get() {
21 return value_;
22 }
23
24 private:
25 int32_t value_;
26
27};
28
29
30int main(int argc, char *argv[]) {
31 shared_ptr<StorageHandler> handler(new StorageHandler());
32 shared_ptr<TProcessor> processor(new StorageProcessor(handler));
33
34 zmq::context_t ctx(1);
35 TZmqServer reqrep_server(processor, ctx, "tcp://0.0.0.0:9090", ZMQ_REP);
Stefan Boluse59b73d2018-05-14 14:48:09 +020036 TZmqServer oneway_server(processor, ctx, "tcp://0.0.0.0:9091", ZMQ_PULL);
David Reiss9f3296b2010-08-31 16:58:41 +000037 TZmqMultiServer multiserver;
38 multiserver.servers().push_back(&reqrep_server);
39 multiserver.servers().push_back(&oneway_server);
40 multiserver.serveForever();
41
42 return 0;
43}