ActivityMQ消息持久化到HANA數據庫

  1. 在apache-activemq-5.9.0\lib中添加hana數據庫驅動包ngdbc.jar
  2. 修改activemq.xml,添加數據鏈接池Bean配置
<bean id="hana-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="com.sap.db.jdbc.Driver"/>
		<property name="url" value="jdbc:sap://192.168.23.144:30015"/>
		<property name="username" value="WIP"/>
		<property name="password" value="Aa123456"/>
</bean>

修改默認的kahadb配置sql

<persistenceAdapter>
     <kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>

改成數據庫

<persistenceAdapter>
	<jdbcPersistenceAdapter	dataSource="#hana-ds"/>
</persistenceAdapter>
  1. 啓動MQ可能會報錯,invalid column ‘XID’,查看hana數據庫發現3個表已經建立,但對比表結構發現確實兩個字段;因此我從新建立表,腳本以下:
CREATE TABLE ACTIVEMQ_ACKS (
	CONTAINER VARCHAR(250) NOT NULL,
	SUB_DEST VARCHAR(250),
	CLIENT_ID VARCHAR(250) NOT NULL,
	SUB_NAME VARCHAR(250) NOT NULL,
	SELECTOR VARCHAR(250),
	LAST_ACKED_ID BIGINT,
	PRIORITY BIGINT NOT NULL DEFAULT 5,
	XID VARCHAR(250)
) ;


CREATE TABLE ACTIVEMQ_LOCK (
	ID BIGINT NOT NULL,
	TIME BIGINT,
	BROKER_NAME VARCHAR(250),
	CONSTRAINT "_SYS_TREE_RS_#186984_#0_#P0" PRIMARY KEY (ID)
) ;

CREATE TABLE ACTIVEMQ_MSGS (
	ID BIGINT NOT NULL,
	CONTAINER VARCHAR(250),
	MSGID_PROD VARCHAR(250),
	MSGID_SEQ BIGINT,
	EXPIRATION BIGINT,
	MSG BLOB,
	PRIORITY BIGINT NOT NULL DEFAULT 5,
	XID VARCHAR(250)
) ;
CREATE INDEX ACTIVEMQ_MSGS_CIDX ON WIP.ACTIVEMQ_MSGS (CONTAINER) ;
CREATE INDEX ACTIVEMQ_MSGS_EIDX ON WIP.ACTIVEMQ_MSGS (EXPIRATION) ;
CREATE INDEX ACTIVEMQ_MSGS_MIDX ON WIP.ACTIVEMQ_MSGS (MSGID_PROD,MSGID_SEQ) ;
CREATE INDEX ACTIVEMQ_MSGS_PIDX ON WIP.ACTIVEMQ_MSGS (PRIORITY) ;
CREATE INDEX ACTIVEMQ_MSGS_XIDX ON WIP.ACTIVEMQ_MSGS (XID) ;

從新啓動mq,啓動成功,測試也OK!apache

相關文章
相關標籤/搜索