diff options
author | Gordon Sim <gsim@apache.org> | 2008-11-07 14:08:29 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2008-11-07 14:08:29 +0000 |
commit | 82cb5b781573bbdd314bae51694ffada3312b5da (patch) | |
tree | 8b0918a47453c49a95a3f0f8510cd425322e3c69 /cpp/examples/failover | |
parent | 897cdd6405ed312afb0a1649ba1c80f7011279e8 (diff) | |
download | qpid-python-82cb5b781573bbdd314bae51694ffada3312b5da.tar.gz |
* Added some doxygen comments for FailoverManager
* Added means for application to alter the order in which urls are tried (or indeed the list of urls to try)
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@712127 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/examples/failover')
-rw-r--r-- | cpp/examples/failover/declare_queues.cpp | 73 | ||||
-rw-r--r-- | cpp/examples/failover/resuming_receiver.cpp | 16 |
2 files changed, 37 insertions, 52 deletions
diff --git a/cpp/examples/failover/declare_queues.cpp b/cpp/examples/failover/declare_queues.cpp index 14e4a1e3cb..a677870c53 100644 --- a/cpp/examples/failover/declare_queues.cpp +++ b/cpp/examples/failover/declare_queues.cpp @@ -19,67 +19,40 @@ * */ -#include <qpid/client/FailoverConnection.h> +#include <qpid/client/FailoverManager.h> #include <qpid/client/Session.h> +#include <qpid/Exception.h> -#include <unistd.h> #include <cstdlib> #include <iostream> -#include <fstream> using namespace qpid::client; -using namespace qpid::framing; - using namespace std; - - - -int -main ( int argc, char ** argv) +int main(int argc, char ** argv) { - if ( argc < 3 ) - { - std::cerr << "Usage: ./declare_queues host cluster_port_file_name\n"; - std::cerr << "i.e. for host: 127.0.0.1\n"; - exit(1); - } - - const char * host = argv[1]; - int port = atoi(argv[2]); - - - try - { - FailoverConnection connection; - FailoverSession * session; - - connection.open ( host, port ); - session = connection.newSession(); - - session->queueDeclare ( "message_queue"); + ConnectionSettings settings; + if (argc > 1) settings.host = argv[1]; + if (argc > 2) settings.port = atoi(argv[2]); + + FailoverManager connection(settings); + try { + bool complete = false; + while (!complete) { + Session session = connection.connect().newSession(); + try { + session.queueDeclare(arg::queue="message_queue"); + complete = true; + } catch (const qpid::TransportFailure&) {} + } + connection.close(); + return 0; + } catch (const std::exception& error) { + std::cout << "Failed:" << error.what() << std::endl; + return 1; + } - /* - session->exchangeBind - ( arg::exchange="amq.direct", - arg::queue="message_queue", - arg::bindingKey="routing_key" - ); - * */ - session->exchangeBind ( "message_queue", - "amq.direct", - "routing_key" - ); - connection.close(); - return 0; - } - catch ( const std::exception& error ) - { - std::cout << error.what() << std::endl; - } - - return 1; } diff --git a/cpp/examples/failover/resuming_receiver.cpp b/cpp/examples/failover/resuming_receiver.cpp index 3c1df92ed1..d1886ce861 100644 --- a/cpp/examples/failover/resuming_receiver.cpp +++ b/cpp/examples/failover/resuming_receiver.cpp @@ -35,13 +35,16 @@ using namespace qpid::framing; using namespace std; -class Listener : public MessageListener, public FailoverManager::Command +class Listener : public MessageListener, + public FailoverManager::Command, + public FailoverManager::ReconnectionStrategy { public: Listener(); void received(Message& message); void execute(AsyncSession& session, bool isRetry); void check(); + void editUrlList(std::vector<Url>& urls); private: Subscription subscription; uint count; @@ -90,14 +93,23 @@ void Listener::execute(AsyncSession& session, bool isRetry) subs.run(); } +void Listener::editUrlList(std::vector<Url>& urls) +{ + /** + * A more realistic algorithm would be to search through the list + * for prefered hosts and ensure they come first in the list. + */ + if (urls.size() > 1) std::rotate(urls.begin(), urls.begin() + 1, urls.end()); +} + int main(int argc, char ** argv) { ConnectionSettings settings; if (argc > 1) settings.host = argv[1]; if (argc > 2) settings.port = atoi(argv[2]); - FailoverManager connection(settings); Listener listener; + FailoverManager connection(settings, &listener); try { connection.execute(listener); |