David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <cstdlib> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 3 | #include <thrift/protocol/TBinaryProtocol.h> |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 4 | |
| 5 | #include "zmq.hpp" |
| 6 | #include "TZmqClient.h" |
| 7 | #include "Storage.h" |
| 8 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 9 | using apache::thrift::std::shared_ptr; |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 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) { |
Stefan Bolus | e59b73d | 2018-05-14 14:48:09 +0200 | [diff] [blame] | 20 | socktype = ZMQ_PUSH; |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 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(); |
CJCombrink | 4a280d5 | 2024-03-14 19:57:41 +0100 | [diff] [blame] | 36 | std::cout << value << '\n'; |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |