blob: 159c25030d5ac2053a21f8a6d0ef57f80a410674 [file] [log] [blame]
David Reiss9f3296b2010-08-31 16:58:41 +00001#include <iostream>
2#include <cstdlib>
Roger Meier49ff8b12012-04-13 09:12:31 +00003#include <thrift/protocol/TBinaryProtocol.h>
David Reiss9f3296b2010-08-31 16:58:41 +00004
5#include "zmq.hpp"
6#include "TZmqClient.h"
7#include "Storage.h"
8
cyy316723a2019-01-05 16:35:14 +08009using apache::thrift::std::shared_ptr;
David Reiss9f3296b2010-08-31 16:58:41 +000010using apache::thrift::transport::TZmqClient;
11using apache::thrift::protocol::TBinaryProtocol;
12
13int 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) {
Stefan Boluse59b73d2018-05-14 14:48:09 +020020 socktype = ZMQ_PUSH;
David Reiss9f3296b2010-08-31 16:58:41 +000021 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}