Servers and tools

Resources

simple_connect.cpp

#include"options.hpp"#include<proton/connection.hpp>#include<proton/connection_options.hpp>#include<proton/container.hpp>#include<proton/messaging_handler.hpp>#include<iostream>#include"fake_cpp11.hpp"classsimple_connect:publicproton::messaging_handler{private:std::stringurl;std::stringuser;std::stringpassword;boolsasl;std::stringmechs;proton::connectionconnection;public:simple_connect(conststd::string&a,conststd::string&u,conststd::string&p,bools,conststd::string&ms):url(a),user(u),password(p),sasl(s),mechs(ms){}voidon_container_start(proton::container&c)OVERRIDE{proton::connection_optionsco;if(!user.empty())co.user(user);if(!password.empty())co.password(password);if(sasl)co.sasl_enabled(true);if(!mechs.empty())co.sasl_allowed_mechs(mechs);connection=c.connect(url,co);}voidon_connection_open(proton::connection&c)OVERRIDE{c.close();}};intmain(intargc,char**argv){std::stringaddress("127.0.0.1:5672/examples");std::stringuser;std::stringpassword;std::stringmechs;boolsasl=false;example::optionsopts(argc,argv);opts.add_value(address,'a',"address","connect and send to URL","URL");opts.add_value(user,'u',"user","authenticate as USER","USER");opts.add_value(password,'p',"password","authenticate with PASSWORD","PASSWORD");opts.add_flag(sasl,'s',"sasl","force SASL authentication with no user specified (Use for Kerberos/GSSAPI)");opts.add_value(mechs,'m',"mechs","allowed SASL mechanisms","MECHS");try{opts.parse();simple_connectconnect(address,user,password,sasl,mechs);proton::container(connect).run();return0;}catch(constexample::bad_option&e){std::cout<<opts<<std::endl<<e.what()<<std::endl;}catch(conststd::exception&e){std::cerr<<e.what()<<std::endl;}return1;}