The client part of a request-response example. Sends requests and prints out responses. Requires an intermediary that supports the AMQP 1.0 dynamic nodes on which the responses are received. The requests are sent through the 'examples' node.
#include "options.hpp"
#include <iostream>
#include <vector>
#include "fake_cpp11.hpp"
private:
std::string url;
std::vector<std::string> requests;
public:
client(const std::string &u, const std::vector<std::string>& r) : url(u), requests(r) {}
receiver_options opts = receiver_options().source(source_options().dynamic(true));
}
void send_request() {
req.
body(requests.front());
}
send_request();
}
if (requests.empty()) return;
std::cout << requests.front() <<
" => " << response.
body() << std::endl;
requests.erase(requests.begin());
if (!requests.empty()) {
send_request();
} else {
}
}
};
int main(int argc, char **argv) {
std::string url("127.0.0.1:5672/examples");
example::options opts(argc, argv);
opts.add_value(url, 'a', "address", "connect and send to URL", "URL");
try {
opts.parse();
std::vector<std::string> requests;
requests.push_back("Twas brillig, and the slithy toves");
requests.push_back("Did gire and gymble in the wabe.");
requests.push_back("All mimsy were the borogroves,");
requests.push_back("And the mome raths outgrabe.");
client c(url, requests);
return 0;
} catch (const example::bad_option& e) {
std::cout << opts << std::endl << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 1;
}