最近有项目要用到activemq,是apache的一个开源项目。其实使用很简单,解压后直接启动就OK了。比较郁闷的一个是,开发要求activemq使用mysql记录消息。原本以为很简单的问题花费了好几天的时间来解决。网上好多的文章也是基于windows下部署的,我全部是在linux下。在安装过程查阅网上的文章,好多问题都没有解决,还是查看了apache的pache库才解决的。在这里记录一下,为有这样需求的童鞋铺铺路。
--------------------------------开始---------------------------------------------
1、软件准备
操作系统:CentOS5.5 32bit
activemq5.5.0:apache找到apache-activemq项目下载,我下载的是tar.gz的包
mysql:这个不说了,编译、rpm随便了,我使用的是rpm安装。
mysql JDBC驱动包:mysql-connector-java-5.1.17.jar
2、安装
1)安装activemq5
#tar zxvf apache-activemq-5.5.0-bin.tar.gz
#mv apache-activemq-5.5.0 /usr/local/activemq
2)修改activemq配置文件
修改${activemq_home}/conf/activemq.xml
找到<broker></broker>,在<broker>中加入 schedulerSupport="true",如下:
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="192.168.64.132" destroyApplicationContextOnStop="true" schedulerSupport="true" >
将默认的<persistenceAdapter>注释掉,加入如下的设置:
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#mysql-ds" useDatabaseLock="false"/>
</persistenceAdapter>
<broker>标签之外配置数据源。下面是MySql的配置信息。 注意,当activemq与mysql安装在一台服务器上时,启动activemq时报连接被拒绝或密码错误的错误时,把localhost改成IP地址。
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
3)手动创建mysql库activemq
mysql>create database activemq;
4)JDBC
mysql JDBC驱动包mysql-connector-java-5.1.17.jar放到${ACTIVEMQ_HOME}/lib/下
3、启动
#${ACTIVEMQ_HOME}/bin/activemq console
这样启动的主要原因是为了实时查看activemq启动过程中是否有错误发生。
4、遇到的问题:
1)
错误:
INFO | Database lock driver override not found for : [mysql-ab_jdbc_driver]. Will use default implementation.
INFO | Attempting to acquire the exclusive lock to become the Master broker
INFO | Failed to acquire lock. Sleeping for 1000 milli(s) before trying again...
INFO | Failed to acquire lock. Sleeping for 1000 milli(s) before trying again...
INFO | Failed to acquire lock. Sleeping for 1000 milli(s) before trying again...
INFO | Failed to acquire lock. Sleeping for 1000 milli(s) before trying again...
INFO | Failed to acquire lock. Sleeping for 1000 milli(s) before trying again...
解决办法:
在persistenceAdapter中添加useDatabaseLock="false"
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#mysql-ds" useDatabaseLock="false" />
</persistenceAdapter>
2)
错误:
Failure Details: Binary logging not possible.
解决:
修改my.cnf,把下面几行打开。
log-bin=mysql-bin
binlog_format=mixed
----------------------------------------结束----------------------------------------------------
写完,收工。