琚大哥给我安排个事儿,ActiveMQ的优化,我去,优化的高端大气上档次的词儿,完全摸不到头脑啊,硬着头皮上吧,网上各种搜配置,最后也算是搞出点名堂了。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName">
<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${jms.brokerURL}" />
<property name="userName" value="${jms.username}" />
<property name="password" value="${jms.password}" />
<!-- 是否异步发送消息 -->
<property name="useAsyncSend" value="true" />
<property name="alwaysSessionAsync" value="false" />
</bean>
<!-- 设置发送连接池,提高性能 -->
<bean id="JmsSenderFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory" ref="jmsFactory" />
<property name="maxConnections" value="100"></property>
</bean>
<!-- 设置接收连接池,提高性能 -->
<bean id="JmsReveiverFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory" ref="jmsFactory" />
<property name="maxConnections" value="100"></property>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="JmsSenderFactory" />
<property name="defaultDestination" ref="destination" />
<!-- 区别它采用的模式:false是p2p;true是订阅 -->
<property name="pubSubDomain" value="false" />
<property name="messageConverter">
<bean class="org.springframework.jms.support.converter.SimpleMessageConverter" />
</property>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate2" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="JmsReveiverFactory" />
<property name="defaultDestination" ref="destination" />
<!-- 区别它采用的模式:false是p2p;true是订阅 -->
<property name="pubSubDomain" value="false" />
<property name="messageConverter">
<bean class="org.springframework.jms.support.converter.SimpleMessageConverter" />
</property>
</bean>
<!-- 发送消息的目的地(一个队列) -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="${jms.queueName}" />
</bean>
<!-- 消息监听 -->
<bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer" lazy-init="false">
<property name="concurrentConsumers" value="${jms.concurrentConsumers}" />
<property name="connectionFactory" ref="JmsReveiverFactory" />
<property name="destinationName" value="${jms.queueName}" />
<property name="messageListener" ref="messageConsumer" />
<property name="pubSubNoLocal" value="true"></property>
</bean>
<!-- 消息消费者 -->
<bean id="messageConsumer"
class="com.voole.jms.MessageConsumer">
<property name="jmsTemplate2" ref="jmsTemplate2"></property>
</bean>
<!-- 消息生产 -->
<bean id="messageProducer"
class="com.voole.jms.MessageProducer">
<property name="jmsTemplate" ref="jmsTemplate"></property>
</bean>
</beans>
上面就是我的xml配置,挑重点讲吧。
在配置 jmsFactory时,注意了,这里面有个严重的问题,
<property name="useAsyncSend" value="true" />
另外还配置了发送连接池和接收连接池来提高性能。
希望有大神看到,再给我提提意见吧,好多不足啊,我这个就当抛砖引玉用。