ActiveMQ 安装使用时遇到的问题

1.ActiveMQ 启动失败,错误日志如下

Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@191d8c1: startup date [Mon Jul 30 20:07:28 CST 2012]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.apache.activemq.hooks.SpringContextHook.run(SpringContextHook.java:30)
at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:782)
at org.apache.activemq.xbean.XBeanBrokerService.stop(XBeanBrokerService.java:122)
at org.apache.activemq.broker.BrokerService.start(BrokerService.java:574)
at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) 
...

上网查好半天看到一个人说是机器名字带有下划线

修改机器名:
1.查看机器名:uname -a 
2.#vi /etc/sysconfig/network //修改HOSTNAME=XX
3.#vi /etc/hosts             //把默认的机器名localhost localhost.localhost localhst改为XX
4.#reboot                    //修改后重启机器

2.持久化配置
broker节点中
 

<persistenceAdapter>
		<jdbcPersistenceAdapter dataSource="#mysql-ds" createTablesOnStartup="true" />
	</persistenceAdapter>

createTablesOnStartup=true 第一次启动 会自动创建3张数据库表,以后启动设为false即可

数据源配置

 

<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://hostip:port/invest?useUnicode=true&characterEncoding=utf-8"/>  
		<property name="username" value="username"/>  
		<property name="password" value="password"/>  
		<property name="poolPreparedStatements" value="true"/>  
</bean>

3.启动报错

参考;http://blog.csdn.net/kimmking/article/details/17754145

java.sql.SQLException: Cannot execute statement: binlogging impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.

这是因为,mysql默认的binlog_format是STATEMENT,而在READ COMMITTED或READ UNCOMMITTED隔离级别下,innodb只能使用的binlog_format是ROW。

而在ActiveMQ的store JDBC实现中(TransactionContext),为了提高并发性能,使用的是READ UNCOMMITTED:

所以,就会出现上面的问题。

解决办法有两个:

1、在mysql里设置binlog_format为ROW,此时binlog会增大,但是一般来说对数据复制支持的更好,建议单机高性能环境下使用。

2、在activemq.xml的jdbcPersistenceAdapter里配置transactionIsolation=“4”,即TRANSACTION_REPEATABLE_READ,此时事务更严格,会影响性能,建议在集群、强实时一致、不强调单机性能的情况下使用。

4.安全权限配置
参考:http://activemq.apache.org/security.html
http://log-cd.iteye.com/blog/585616

<plugins>
	  <!-- Configure authentication; Username, passwords and groups -->
	  <simpleAuthenticationPlugin>
		  <users>
			  <authenticationUser username="system" password="manager" groups="users,admins"/>
			  <authenticationUser username="user" password="password" groups="users"/>
			  <authenticationUser username="guest" password="password" groups="guests"/>
			  <authenticationUser username="invest" password="invest" groups="investQueue"/>
		  </users>
	  </simpleAuthenticationPlugin>
	 
	  <!--  Lets configure a destination based authorization mechanism -->
	  <authorizationPlugin>
		<map>
		  <authorizationMap>
			<authorizationEntries>
			  <authorizationEntry queue="queue.group.uum" read="users" write="users" admin="users" />
			  <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
			  <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />
			  <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
	 
			  <authorizationEntry queue="TEST.Q" read="guests" write="guests" />
			  <authorizationEntry queue="queue_invest" read="investQueue " write="investQueue " admin="investQueue"/>
	 
			  <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
			  <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />
			  <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
	 
			  <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users,investQueue" write="guests,users,investQueue" admin="guests,users,investQueue"/>
			</authorizationEntries>
		  </authorizationMap>
		</map>
	  </authorizationPlugin>
	</plugins>


版权声明:本文为running_snail_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。