The server part of a request-response example, that receives requests via the examples node, converts the body to uppercase and sends the result back to the indicated reply address.
#include "options.hpp"
#include <proton/connection.hpp>
#include <proton/container.hpp>
#include <proton/default_container.hpp>
#include <proton/message.hpp>
#include <proton/message_id.hpp>
#include <proton/messaging_handler.hpp>
#include <proton/thread_safe.hpp>
#include <proton/tracker.hpp>
#include <proton/url.hpp>
#include <iostream>
#include <map>
#include <string>
#include <cctype>
#include "fake_cpp11.hpp"
private:
typedef std::map<std::string, proton::sender> sender_map;
sender_map senders;
public:
server(const std::string &u) : url(u) {}
std::cout << "server connected to " << url << std::endl;
}
std::string to_upper(const std::string &s) {
std::string uc(s);
size_t l = uc.size();
for (size_t i=0; i<l; i++)
uc[i] = static_cast<char>(std::toupper(uc[i]));
return uc;
}
std::cout <<
"Received " << m.
body() << std::endl;
reply.
body(to_upper(proton::get<std::string>(m.
body())));
if (!senders[reply_to]) {
}
senders[reply_to].
send(reply);
}
};
int main(int argc, char **argv) {
std::string address("amqp://0.0.0.0:5672/examples");
example::options opts(argc, argv);
opts.add_value(address, 'a', "address", "listen on URL", "URL");
try {
opts.parse();
server srv(address);
proton::default_container(srv).run();
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;
}