ActiceMQ-CPP消息插件是CMS的一种实现,是一个能够与ActiveMQ进行通信的C++客户端库,ActiveMQ-CPP的架构设计能够支持可插拨的传输协议和消息封装格式,并且支持客户端容量,能够与ActiveMQ高效和便捷地进行通信,并且提供一系列跨平台的类Java API的特性,如多线程处理、I/O、sockets等

在进行activemq插件开发之前我们需要有以下几个操作:

<1>activemq-cpp的安装

activemq-cpp的编译依赖libuuid,apr,apr-util,apr-iconv,openssl几个库,目前库资源比较难找,附上自己使用的资源一份。下载地址:https://pan.baidu.com/s/1AdXdKsr1NwJRzkyD2gXjhg

1.1 安装apr

解压 tar -xf apr-1.4.6tar.gz

配置apr源码,并指定路径 ./configure --prefix=/usr/local/apr

安装 sudo make & make install

1.2安装apr-iconv

解压 tar -xf apr-iconv-1.2.1.tar

配置源码,并指定路径 ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr

安装 sudo make & make install

1.3安装apr-util

解压 tar -xf apr-util-1.4.1.tar.gz

配置源码,并指定路径 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

安装 sudo make & make install

1.4 安装activemq-cpp

解压 tar -xf activemq-cpp.tar.gz

配置源码,并指定路径  ./configure --prefix=/usr/local/activemq-cpp --with-apr=/usr/local/apr/ --with-openssl=/usr/local/openssl

安装 sudo make & make install

安装完成,不想编译源码的可以下载我整理好的动态库https://pan.baidu.com/s/1AymD_IlazGUPppjsXqwtsA

然后在

/etc/ld.so.conf中加入/usr/local/lib這一行
执行 /sbin/ldconfig -v     调用这些动态库就可以了
 
<2>eos中添加activemq插件
首先每个plugin都只初始化一次,其次因为都在app中注册过,大家互相是可以调用的
2.1添加所需头文件
除了需要向eos中做一些注册和订阅通知意以外
activemq的创建,存取数据都可参照activemq-cpp中example实例
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Long.h>
#include <decaf/util/Date.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <activemq/library/ActiveMQCPP.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 <decaf/lang/System.h>
#include <decaf/lang/Integer.h>
#include <cms/Destination.h>
#include <cms/MessageProducer.h> using namespace activemq;    //使用
using namespace activemq::core;
using namespace decaf;
using namespace decaf::lang;
using namespace decaf::util;
using namespace decaf::util::concurrent;
using namespace cms;
using namespace std; class activemq_plugin : public plugin<activemq_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((activemq_plugin)) //在application单例中注册当前插件类
activemq_plugin();
virtual ~activemq_plugin(); void plugin_initialize(const variables_map& options);   //初始化连接mq设置 void sendTxtMsg(const string& textMsg);        //发送消息 }

  

2.2线程共享数据加密

eos中大量采用boost中的算法,线程数据加锁采用pthread_mutex_t ,所有异步或同步线程中对内存数据同时存在读写的都得使用锁

pthread_mutex_t       m_mutex;      //锁定义

pthread_mutex_init(&m_mutex, NULL);    //初始化锁

pthread_mutex_lock(&m_mutex);        //加锁
pthread_mutex_unlock(&m_mutex);    //解锁

boost::thread m_thread(threadfunc);        //初始化线程

2.3eos每个plugin之间得互相访问

app().get_plugin<pluginA>()获取pluginA实例进行访问

<3>编译当前plugin

编写CMakeLists,make运行就完成了

file(GLOB HEADERS "include/eosio/activemq_plugin/*.hpp")
add_library( activemq_plugin
activemq_plugin.cpp
IniParser.cpp
${HEADERS} ) include_directories(
./
/usr/local/include/activemq-cpp-3.10.0/
/diskwork/work/activemq-cpp/activemq-cpp/src/main/
/usr/local/apr/include/apr-1/
/home/anlg/opt/boost/include/
./include/eosio/activemq_plugin/
${CMAKE_CURRENT_SOURCE_DIR}/../chain_plugin/include
)
link_directories(
./
/usr/local/lib/
)
target_link_libraries( activemq_plugin chain_plugin activemq-cpp appbase)
target_include_directories( activemq_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../chain_interface/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/appbase/include" )

  

最新文章

  1. mina通信 demo
  2. event事件对象和clientX,clientY
  3. Mybatis 异常: The content of elements must consist of well-formed character data or markup
  4. 关于css布局的几篇文章
  5. 如何设置session过期时间为30分钟
  6. [Web API] 如何让 Web API 统一回传格式以及例外处理
  7. window 下cygwin开启了后来又关闭了
  8. Java联网技术之一TCP
  9. SpringMVC第七篇【RESTful支持、拦截器】
  10. Linux自启动执行脚本方法
  11. 锋利的jQuery初学(4)
  12. python:windows下python2.7安装mysql-python失败【转】
  13. sqli-labs第一节 get-字符型注入
  14. 深入Golang之sync.Pool详解
  15. ANSI编码导致的乱码
  16. vim Google style format
  17. SQL 流水账余额查询
  18. idea javamaven项目 连接sqlserver 数据库方法
  19. nginx 虚拟主机、反向代理服务器及负载均衡,多台主机分离php-fpm实验
  20. 在Win环境下配置java的环境进行开发步骤

热门文章

  1. Python基础之模块:6、hashlib模块 subprocess模块 logging模块
  2. Sprint产品待办列表的优先级要怎么排?
  3. MySQL数据库的性能分析 ---图书《软件性能测试分析与调优实践之路》-手稿节选
  4. C#多线程之线程基础篇
  5. 倍福Ads协议通信测试
  6. 思维分析逻辑 3 DAY
  7. Windows之应用安装程序 —— winget
  8. JDK 8 Stream 流 用 法
  9. Azure DevOps Server 用户组加入 Azure AD Domain Service 管理用户
  10. 【翻译】rocksdb调试指引