mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
e59b73d3c2
* New style for Python is default now. * Symbols were replaced in newer versions of ZeroMQ (>=3.0). * Use Thrift's abstraction for `shared_ptr` instead of Boost. * Symbols were replaced in Python as well.
41 lines
934 B
C++
41 lines
934 B
C++
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <thrift/protocol/TBinaryProtocol.h>
|
|
|
|
#include "zmq.hpp"
|
|
#include "TZmqClient.h"
|
|
#include "Storage.h"
|
|
|
|
using apache::thrift::stdcxx::shared_ptr;
|
|
using apache::thrift::transport::TZmqClient;
|
|
using apache::thrift::protocol::TBinaryProtocol;
|
|
|
|
int main(int argc, char** argv) {
|
|
const char* endpoint = "tcp://127.0.0.1:9090";
|
|
int socktype = ZMQ_REQ;
|
|
int incr = 0;
|
|
if (argc > 1) {
|
|
incr = atoi(argv[1]);
|
|
if (incr) {
|
|
socktype = ZMQ_PUSH;
|
|
endpoint = "tcp://127.0.0.1:9091";
|
|
}
|
|
}
|
|
|
|
zmq::context_t ctx(1);
|
|
shared_ptr<TZmqClient> transport(new TZmqClient(ctx, endpoint, socktype));
|
|
shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
|
|
StorageClient client(protocol);
|
|
transport->open();
|
|
|
|
if (incr) {
|
|
client.incr(incr);
|
|
usleep(50000);
|
|
} else {
|
|
int value = client.get();
|
|
std::cout << value << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|