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