// 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";
static const char *PAYLOAD = "<data>\r\n    <id>123</id>\r\n   <name>ABC</name>\r\n</data>";

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);
    MessageProducer *mp = ses->createProducer(q);
    for(int i = 0; i < 3; i++)
    {
        Message *msg = ses->createTextMessage(PAYLOAD);
        mp->send(msg);
        delete msg;
    }
    delete mp;
    delete q;
    delete ses;
    delete con;
    delete cf;
    ActiveMQCPP::shutdownLibrary();
    return 0;
}
