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