ActiveMQ download includes some CPP files to be build by gcc. It would be interesting to use VS 2015 C++ to build a listener.
(1) http://activemq.apache.org download to c:\ActiveMQ has bin\x64 install as service. Need java 64-bit using java -d64 -version to check.
(2) Web page management tools: http://localhost:8161 admin/admin
(3) need to compile C# sample, Nuget Apache NMS two download to run publisher and Listener. C++ code only need publisher to run pushing data out
(4) VC++ in VS2015 need a Win32 Console project. I can only get Win32 Config+Tageting Win8.1 working. Win10, X86 or X64 have lib missing issues.
(5) there are plenty of header include, Lib include and lib dependencies as state below:
VC++ header include
C:\working\apr-1.5.2\include;C:\working\activemq-cpp-library-3.9.2\src\main;
VC++ Lib directory
C:\working\apr-1.5.2\LibD;C:\working\activemq-cpp-library-3.9.2\vs2010-build\Win32\Debug\activemq-cpp
Link/Input/Additional Dependencies
C:\working\activemq-cpp-library-3.9.2\vs2010-build\Win32\Debug\libactivemq-cpp.lib;C:\working\apr-1.5.2\LibD\apr-1.lib;C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\WSock32.lib;C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\WS2_32.lib;C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\RpcRT4.lib;
(6) as Shown in (5), there are apr (apache portable runtime), activeMQ cpp to be build from source. one is old C++/C code and one is VS 2010 code, while the latter need to include header of apr, there are not much lib or dependencies struggle.
(7) a lot of time spend on unresolved symbols, as shown in above reference to Platform SDK, There are some file by file linker dependencies like WSock32.lib,WS3_32.lib. really drive me crazy.
Here is the quite simple code that can run against ActiveMQ C# Publisher sample for tcp and failover protocol.
#pragma once
#include "stdafx.h"
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/core/ActiveMQConnection.h>
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/System.h>
#include <activemq/util/Config.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>
using namespace activemq;
using namespace activemq::core;
using namespace decaf::lang;
using namespace cms;
using namespace std;
int main()
{
activemq::library::ActiveMQCPP::initializeLibrary();
{
ActiveMQConnectionFactory factory;
factory.setBrokerURI(std::string("tcp://localhost:61616"));
// factory.setBrokerURI(std::string("failover://(tcp://localhost:61616,tcp://localhost:61616)"));
std::auto_ptr<Connection> connection(factory.createConnection("admin", "password"));
std::auto_ptr<Session> session(connection->createSession());
std::auto_ptr<Destination> dest(session->createTopic("event"));
std::auto_ptr<MessageConsumer> consumer(session->createConsumer(dest.get()));
connection->start();
long long start = System::currentTimeMillis();
long long count = 0;
while (true) {
std::auto_ptr<Message> message(consumer->receive());
const TextMessage* txtMsg = dynamic_cast<const TextMessage*>(message.get());
if (txtMsg != NULL) {
std::string body = txtMsg->getText();
if (body == "SHUTDOWN") {
cout << "done " << endl;
break;
}
else
{
count++;
cout << "received message " << body << " " << count << endl;
}
}
}
getchar();
}
activemq::library::ActiveMQCPP::shutdownLibrary();
return 0;
}
Sunday, February 14, 2016
ActiveMQ C++/Win32 Listener
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment