-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.cpp
69 lines (50 loc) · 1.92 KB
/
publisher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "publisher.h"
#include <activemq/util/Config.h>
#include <decaf/lang/System.h>
#include <decaf/lang/Runnable.h>
#include <decaf/lang/Integer.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/library/ActiveMQCPP.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/Destination.h>
#include <cms/MessageProducer.h>
#include <cms/TextMessage.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
#include <sstream>
using namespace cms;
using namespace activemq;
using namespace activemq::core;
using namespace decaf;
using namespace decaf::lang;
std::string CMSPublisher::send_to_queue(std::string payload){
activemq::library::ActiveMQCPP::initializeLibrary();
std::string user = "admin";
std::string password = "password";
std::string host = "192.168.99.1";
int port = Integer::parseInt("61616");
std::string destination = "_event";
std::string strDestination = "_reply_event";
//std::string body = "<payload goes here>";
std::string correlation_id = "AZCorrelationId";
{
ActiveMQConnectionFactory factory;
factory.setBrokerURI(std::string("tcp://") + host + ":" + Integer::toString(port));
std::auto_ptr<TextMessage> message;
std::auto_ptr<Connection> connection(factory.createConnection(user, password));
std::auto_ptr<Session> session(connection->createSession());
connection->start();
std::auto_ptr<Destination> dest(session->createQueue(destination));
std::auto_ptr<MessageProducer> producer(session->createProducer(dest.get()));
producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
message.reset(session->createTextMessage(payload));
message->setCMSCorrelationID(correlation_id);
producer->send(message.get());
connection->close();
}
activemq::library::ActiveMQCPP::shutdownLibrary();
return correlation_id;
}