配置activemq5使用mysql資料庫

來源:互聯網
上載者:User

最近有項目要用到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

 

----------------------------------------結束----------------------------------------------------

寫完,收工。

 

本文出自 “目標→Linux” 部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.