]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #include <iostream> |
2 | #include <cstdlib> | |
3 | #include <thrift/protocol/TBinaryProtocol.h> | |
4 | ||
5 | #include "zmq.hpp" | |
6 | #include "TZmqClient.h" | |
7 | #include "Storage.h" | |
8 | ||
9 | using apache::thrift::std::shared_ptr; | |
10 | using apache::thrift::transport::TZmqClient; | |
11 | using apache::thrift::protocol::TBinaryProtocol; | |
12 | ||
13 | int main(int argc, char** argv) { | |
14 | const char* endpoint = "tcp://127.0.0.1:9090"; | |
15 | int socktype = ZMQ_REQ; | |
16 | int incr = 0; | |
17 | if (argc > 1) { | |
18 | incr = atoi(argv[1]); | |
19 | if (incr) { | |
20 | socktype = ZMQ_PUSH; | |
21 | endpoint = "tcp://127.0.0.1:9091"; | |
22 | } | |
23 | } | |
24 | ||
25 | zmq::context_t ctx(1); | |
26 | shared_ptr<TZmqClient> transport(new TZmqClient(ctx, endpoint, socktype)); | |
27 | shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport)); | |
28 | StorageClient client(protocol); | |
29 | transport->open(); | |
30 | ||
31 | if (incr) { | |
32 | client.incr(incr); | |
33 | usleep(50000); | |
34 | } else { | |
35 | int value = client.get(); | |
36 | std::cout << value << std::endl; | |
37 | } | |
38 | ||
39 | return 0; | |
40 | } |