ActiveMQ CPP

ActiveMQ CPP是用C++语言访问ActiveMQ的客户端开发库,也称cms(cpp message service),安装cms开发库需要先安装一些基础库。

如下:

 (1)autoconf,automake,libtool

curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
tar -xzf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local/autoconf/&& make && sudo make install curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz
tar -xzf automake-1.14.tar.gz
cd automake-1.14
./configure --prefix=/usr/local/automake/&& make && sudo make install curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
tar -xzf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure --prefix=/usr/local/libtool/&& make && sudo make install

(2)cppunit

打开http://activemq.apache.org/cms/building.html页面,这里介绍了cms build时用到的依赖库。 
执行下面命令完成cppunit下载: 
curl -OL https://sourceforge.net/projects/cppunit/files/cppunit/1.12.1/ 
这里选择1.12.1版本,获取到下载地址后,在linux下可以用wget命令直接下载,或者下载完成后传到linux系统中。

tar解压后,进入目录,编译三部曲,configure、make、make install(install需要root权限):

./configure --prefix=/usr/local/cppunit/
make
make install

执行完后在/usr/local/cppunit/目录下可以看到头文件和库文件。

注:我是Ubuntu下安装的,按上述步骤安装到make的时候遇到了两个问题,解决方法如下:

1.当进行make的时候, 则出现了如下的错误:

从上面的提示可以看出, 问题是出在DllPlugInTester编译的过程中, 出现这个问题的可能原因是g++的版本为4.8.1.

解决办法

cd到DllPlugInTester目录下,

LDFLAGS=后面加上, LDFLAGS=-Wl,--no-as-need, 然后再次make, 如果在其他的目录又出现类似的问题, 用同样的方法进行处理即可.

2.make又出现了以下错误:

解决方法:./configure LDFLAGS='-ldl'

      make

(3)apr

apr的全称为Apache Portable Runtime(Apache可移植运行时),Apache旗下有很多开源软件。

apr介绍页面: 
http://apr.apache.org/download.cgi 
执行下面命令完成apr下载:

curl -OL  http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz

同上,解压进入目录,三部曲:

./configure --prefix=/usr/local/apr/
make
make install

 

(4)apr-util

执行下面命令完成APR-util的下载: 
 curl -OL http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz

解压编译:

./configure --prefix=/usr/local/aprutil --with-apr=/usr/local/apr/
make
make install

(5)apr-iconv

执行下面的命令完成APR iconv 的下载: 
  curl -OL   http://mirrors.hust.edu.cn/apache//apr/apr-iconv-1.2.1.tar.gz

解压编译:

./configure --prefix=/usr/local/apr-iconv/ --with-apr=/usr/local/apr/
make
make install

(6)openssl

执行下面的命令完成openssl 的下载: 
 curl -OL  http://www.openssl.org/source/openssl-1.0.0a.tar.gz

解压编译: 
./config --prefix=/usr/local/openssl/ 
make 
make install 

若出现报错 
cms.pod around line 457: Expected text after =item, not a number 
在root权限下,执行rm -f /usr/bin/pod2man 然后重新make install

(7)ActiveMQ-CPP

这里选择最新的ActiveMQ-CPP 3.9.4版本,下载页面为: 
http://activemq.apache.org/cms/2017/02/24/activemq-cpp-v394-released.html

解压编译:

./configure --prefix=/usr/local/ActiveMQ-CPP --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/aprutil --with-cppunit=/usr/local/cppunit --with-openssl=/usr/local/openssl
make
make install

  

测试程序

至此编译工作完成,在/usr/local目录下生成了6个目录,分别为ActiveMQ-CPP、apr、apr-iconv、aprutil、cppunit、openssl。

下面编写一段测试代码(test.cpp),用于检测cms开发库是否可用。

#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/System.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/TextMessage.h>
#include <cms/BytesMessage.h>
#include <cms/MapMessage.h>
#include <cms/ExceptionListener.h>
#include <cms/MessageListener.h> #include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory> using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;
using namespace std; int main()
{
activemq::library::ActiveMQCPP::initializeLibrary();
Connection* conn;
Session* sess;
Destination* dest;
MessageProducer* producer; std::string brokerurl("failover:(tcp://192.168.1.113:61616)");
try
{
auto_ptr<ConnectionFactory> connFactory(ConnectionFactory::createCMSConnectionFactory(brokerurl));
conn = connFactory->createConnection();
conn->start(); sess = conn->createSession(Session::AUTO_ACKNOWLEDGE);
dest = sess->createQueue("QueueFromLinuxTest"); producer = sess->createProducer(dest);
producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); string text("Hello ActiveMQ from LinuxTest");
for (int i = 0; i < 3; ++i)
{
TextMessage* msg = sess->createTextMessage(text);
msg->setIntProperty("IntProp1", i);
producer->send(msg);
cout << "SEND-> " << text << endl;
delete msg;
}
}
catch (CMSException& e)
{
e.printStackTrace();
} try {
delete dest;
dest = NULL;
delete producer;
producer = NULL; if (NULL != sess)
sess->close();
if (NULL != conn)
conn->close(); delete sess;
sess = NULL;
delete conn;
conn = NULL;
}
catch (CMSException& e)
{
e.printStackTrace();
} cout << "test end" << endl;
activemq::library::ActiveMQCPP::shutdownLibrary();
}

  

编译命令: 
g++ test.cpp -I/usr/local/ActiveMQ-CPP/include/activemq-cpp-3.9.4 -I/usr/local/apr/include/apr-1 -L/usr/local/ActiveMQ-CPP/lib -lactivemq-cpp 

其中-I指定了两个include目录,-L指定了一个库目录,-l指定了一个链接库。

运行时,需要将libactivemq-cpp.so、libactivemq-cpp.so.19、libactivemq-cpp.so.19.0.3这3个运行时库复制到/usr/lib64目录下。

参考:http://blog.csdn.net/lgh1700/article/details/51055784

Linux下安装ActiveMQ CPP的更多相关文章

  1. Linux下安装 activemq 并指定jdk 1.8

    1. 下载安装包 <apache-activemq-5.15.4-bin.tar.gz> 下载地址:https://pan.baidu.com/s/18xzjBAchjWqsHNA1HuY ...

  2. linux下安装或升级GCC4.8.2,以支持C++11标准[转]

    在编译kenlm的时候需要安装gcc, 然后还需要安装g++. g++安装命令:sudo apt-get install g++ ----------------------以下为网上转载内容,加上自 ...

  3. Linux下安装 Posgresql 并设置基本参数

    在Linux下安装Postgresql有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装.各个版本的Linux都内置了Postgresql,所以可直接通过命令行安装便可.本文用的是Cen ...

  4. Linux下安装Tomcat服务器和部署Web应用

    一.上传Tomcat服务器

  5. Linux下安装使用Solr

    Linux下安装使用Solr 1.首先下载Solr.mmseg4j分词包.tomcat并解压,这用google.百度都可以搜索得到下载地址. 2.因为要使用到中文分词,所以要设置编码,进入tomcat ...

  6. Linux下安装tar.gz类型的jdk,并配置环境变量

    近期因要学习一门技术,必须在Linux下运行,故开始学习如何使用Linux. 在安装jdk时出现了困难,环境变量配置不成功,花了一天时间才搞定,特分享出来,供大家参考. Linux下安装jdk,步骤如 ...

  7. Linux下安装和配置JDK与Tomcat(升级版)

    在这个版本 Linux下安装和配置JDK与Tomcat(入门版) 的基础上优化升级 1.下载相关软件 apache-tomcat-6.0.37.tar.gz jdk-6u25-linux-i586-r ...

  8. Linux下安装cmake

    cmake是一个跨平台的编译工具,特点是语句简单,编译高效,相对于原有的automake更为高效,接下来说明在Linux下安装cmake工具的过程 首先去cmake官网下载cmake安装包,下载界面网 ...

  9. linux下安装安装pcre-8.32

    linux下安装安装pcre-8.32 ./configure --prefix=/usr/local/pcre 出现以下错误 configure: error: You need a C++ com ...

随机推荐

  1. C#仪器数据文件解析-XPS文件

    XPS为微软推出的类似于Adobe PDF的一种文件格式,个人认为XPS很好,但毕竟PDF已经被大家所熟知,因此XPS的使用很少,也少有仪器数据输出为该格式. XPS百度百科:https://baik ...

  2. C语言程序设计第一作业

    C语言程序设计第一作业 实验总结 (一) 1.题目:输入圆的半径,求圆周长和面积 2.流程图: 3.测试数据及运行结果: 4.实验分析: 问题1: 出现了错误 原因:是在赋值那写反了 解决方法:应该是 ...

  3. java 虚拟机与并发处理几个问题简要(二)

    六.两个重要的概念性问题: 1.同步:要保持数据的一致性,就需要一种保证并发进程正确执行顺序的机制.这种机制就是 进程同步(Process Synchronization). 竞争资源的多个进程按着特 ...

  4. Python系列之文件操作、冒泡算法、装饰器、及递归

    文件处理 python对文件进行读写操作的方法与具体步骤,包括打开文件.读取内容.写入文件.文件中的内容定位.及关闭文件释放资源等 open().file(),这个两函数提供了初始化输入\输出(I\O ...

  5. linux安装禅道的步骤

    linux一键安装禅道:1.禅道帮助文档:http://www.zentao.net/book/zentaopmshelp/90.html 2.修改Apache的端口号:/opt/zbox/zbox ...

  6. OpenWRT添加模块 Makefile和Config.in

    添加模块编译 在网上找了一下,很多关于编译Openwrt系统的资料,不过这些事情芯片厂商提供的开发包都已经办得妥妥了,但是没有找到系统介绍的资料,添加一个包的介绍有不多,其中有两个很有参考价值: ht ...

  7. eclipse环境下,java操作MySQL的简单演示

    首先先通过power shell 进入MySQL 查看现在数据库的状态(博主是win10系统) 右键开始,选择Windows powershell ,输入MySQL -u用户名 -p密码 选择数据库( ...

  8. Spring批量更新batchUpdate提交和Hibernate批量更新executeUpdate

    1:先看hibernate的批量更新处理. 版本背景:hibernate 5.0.8 applicationContext.xml 配置清单: <?xml version="1.0&q ...

  9. 第一篇bolg

    仅以此篇谨记自己,以后加油

  10. 项目总结二:模块管理之requireJS

    项目开发前期,对究竟用requireJS 还是sea.js 进行讨论,最后采用requireJS,但是后期遇到了问题--当谷歌地图不能加载时,整个页面卡死的状况. requirejs 的作用: 防止j ...