// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
#include <iostream>

using namespace std;

#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/library/ActiveMQCPP.h>
#include <activemq/util/Config.h>

using namespace activemq::core;
using namespace activemq::library;
using namespace cms;

static const char *SERVER = "tcp://192.168.1.99:61616";
static const char *UN = "arne";
static const char *PW = "topsecret";
static const char *QNAME = "TestQ";

int main()
{
    ActiveMQCPP::initializeLibrary();
    ConnectionFactory *cf = ConnectionFactory::createCMSConnectionFactory(SERVER);
    Connection *con = cf->createConnection(UN, PW);
    con->start();
    Session *ses = con->createSession(Session::AUTO_ACKNOWLEDGE);
    Queue *q = ses->createQueue(QNAME);
    MessageConsumer *mc = ses->createConsumer(q);
    for(;;)
    {
        TextMessage *msg = (TextMessage *)mc->receive();
        cout << msg->getText() << endl;    
        delete msg;
    }
    delete mc;
    delete q;
    delete ses;
    delete con;
    delete cf;
    ActiveMQCPP::shutdownLibrary();
    return 0;
}
