This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Use of Get()
Skip to end of metadata
Go to start of metadata

Note that SubscriptionManager::get() will cause a synchronous interaction pattern with the broker where a local queue get() will not. See example below of comparing them

Using SubscriptionManager::get():

#include <qpid/client/Connection.h> 
#include <qpid/client/Session.h> 
#include <qpid/client/Message.h> 
#include <qpid/client/SubscriptionManager.h> 
#include <qpid/sys/Time.h> 
#include <unistd.h> 
#include <cstdlib> 
#include <iostream> 
using namespace qpid::client; 
using namespace qpid::framing; 
int main(int argc, char** argv) { 
    const char* host = argc>1 ? argv[1] : "127.0.0.1"; 
    int port = argc>2 ? atoi(argv[2]) : 5672; 
    Connection connection; 
    try { 
        connection.open(host, port); 
        Session session = connection.newSession(); 
        SubscriptionManager subs(session); 
        Message m; 
        while (!subs.get(m, "test­queue", 1*qpid::sys::TIME_SEC)) { 
            std::cout << "No message available" << std::endl; 
        } 
        std::cout << "Got: " << m.getData() << std::endl; 
        session.close(); 
        connection.close(); 
        return 0; 
    } catch(const std::exception& error) { 
        std::cout << error.what() << std::endl; 
    } 
    return 1; 
} 

Using a LocalQueue directly:

#include <qpid/client/Connection.h> 
#include <qpid/client/Session.h> 
#include <qpid/client/Message.h> 
#include <qpid/client/SubscriptionManager.h> 
#include <qpid/sys/Time.h> 
#include <unistd.h> 
#include <cstdlib> 
#include <iostream> 
using namespace qpid::client; 
using namespace qpid::framing; 
int main(int argc, char** argv) { 
    const char* host = argc>1 ? argv[1] : "127.0.0.1"; 
    int port = argc>2 ? atoi(argv[2]) : 5672; 
    Connection connection; 
    try { 
        connection.open(host, port); 
        Session session = connection.newSession(); 
        SubscriptionManager subs(session); 
        LocalQueue incoming; 
        subs.subscribe(incoming, "test­queue"); 
        Message m; 
        while (!incoming.get(m, 1*qpid::sys::TIME_SEC)) { 
            std::cout << "No message available" << std::endl; 
        } 
        std::cout << "Got: " << m.getData() << std::endl; 
        session.close(); 
        connection.close(); 
        return 0; 
    } catch(const std::exception& error) { 
        std::cout << error.what() << std::endl; 
    } 
    return 1; 
}