测试mq消费者
This commit is contained in:
parent
dd78fd64b9
commit
c9699653a4
|
@ -85,7 +85,7 @@
|
||||||
</webApp>
|
</webApp>
|
||||||
<connectors>
|
<connectors>
|
||||||
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
|
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
|
||||||
<port>8088</port>
|
<port>8080</port>
|
||||||
</connector>
|
</connector>
|
||||||
</connectors>
|
</connectors>
|
||||||
<reload>automatic</reload>
|
<reload>automatic</reload>
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package com.zheng.cms.controller;
|
package com.zheng.cms.controller;
|
||||||
|
|
||||||
|
import com.zheng.common.util.JmsUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jms.core.JmsTemplate;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.jms.Destination;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息队列controller
|
* 消息队列controller
|
||||||
|
@ -16,19 +22,22 @@ public class ActiveMQController extends BaseController {
|
||||||
|
|
||||||
private static Logger _log = LoggerFactory.getLogger(ActiveMQController.class);
|
private static Logger _log = LoggerFactory.getLogger(ActiveMQController.class);
|
||||||
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// JmsTemplate jmsTemplate;
|
JmsTemplate jmsQueueTemplate;
|
||||||
//
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// Destination defaultQueueDestination;
|
Destination defaultQueueDestination;
|
||||||
//
|
|
||||||
// @RequestMapping("/send")
|
@RequestMapping("/send")
|
||||||
// @ResponseBody
|
@ResponseBody
|
||||||
// public Object send() {
|
public Object send() {
|
||||||
// for (int i = 0; i < 1000; i ++) {
|
long start = System.currentTimeMillis();
|
||||||
// JmsUtil.sendMessage(jmsTemplate, defaultQueueDestination, "消息" + i);
|
for (int i = 0; i < 100; i ++) {
|
||||||
// }
|
_log.info("发送消息" + (i + 1));
|
||||||
// return "success";
|
JmsUtil.sendMessage(jmsQueueTemplate, defaultQueueDestination, "消息" + (i + 1));
|
||||||
// }
|
}
|
||||||
|
_log.info("发送消息消耗时间" + (System.currentTimeMillis() - start));
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -27,8 +27,8 @@ public class defaultQueueMessageListener implements MessageListener {
|
||||||
public void run() {
|
public void run() {
|
||||||
TextMessage textMessage = (TextMessage) message;
|
TextMessage textMessage = (TextMessage) message;
|
||||||
try {
|
try {
|
||||||
_log.info("defaultQueueMessageListener接收到:{}", textMessage.getText());
|
_log.info("cms-web接收到:{}", textMessage.getText());
|
||||||
} catch (JMSException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,38 +5,43 @@
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"
|
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"
|
||||||
default-autowire="byName">
|
default-autowire="byName">
|
||||||
|
|
||||||
<!--<!– 连接工厂 –>-->
|
<!-- 连接工厂 -->
|
||||||
<!--<bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">-->
|
<bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||||
<!--<property name="brokerURL" value="${AvtiveMQ.brokerURL}"/>-->
|
<property name="brokerURL" value="${AvtiveMQ.brokerURL}"/>
|
||||||
<!--</bean>-->
|
</bean>
|
||||||
<!--<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">-->
|
<!--<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">-->
|
||||||
<!--<property name="connectionFactory" ref="activeMqConnectionFactory"/>-->
|
<!--<property name="connectionFactory" ref="activeMqConnectionFactory"/>-->
|
||||||
<!--<property name="maxConnections" value="10"/>-->
|
<!--<property name="maxConnections" value="10"/>-->
|
||||||
<!--</bean>-->
|
<!--</bean>-->
|
||||||
<!--<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">-->
|
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||||
<!--<property name="targetConnectionFactory" ref="pooledConnectionFactory"/>-->
|
<property name="targetConnectionFactory" ref="activeMqConnectionFactory"/>
|
||||||
<!--</bean>-->
|
<property name="sessionCacheSize" value="100"/>
|
||||||
<!--<!– 点对点队列 –>-->
|
</bean>
|
||||||
<!--<bean id="defaultQueueDestination" class="org.apache.activemq.command.ActiveMQQueue">-->
|
<!-- 点对点队列 -->
|
||||||
<!--<constructor-arg index="0" value="com.zheng.cms.queue.default" />-->
|
<bean id="defaultQueueDestination" class="org.apache.activemq.command.ActiveMQQueue">
|
||||||
<!--</bean>-->
|
<constructor-arg index="0" value="com.zheng.cms.queue.default"/>
|
||||||
<!--<!– 一对多队列 –>-->
|
</bean>
|
||||||
<!--<!–-->
|
<!-- 一对多队列 -->
|
||||||
<!--<bean id="defaultTopicDestination" class="org.apache.activemq.command.ActiveMQTopic">-->
|
<bean id="defaultTopicDestination" class="org.apache.activemq.command.ActiveMQTopic">
|
||||||
<!--<constructor-arg index="0" value="com.zheng.cms.topic.default" />-->
|
<constructor-arg index="0" value="com.zheng.cms.topic.default"/>
|
||||||
<!--</bean>-->
|
</bean>
|
||||||
<!--–>-->
|
|
||||||
|
|
||||||
<!--<!– 生产者 –>-->
|
<!-- 生产者 -->
|
||||||
<!--<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">-->
|
<bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
|
||||||
<!--<property name="connectionFactory" ref="connectionFactory"/>-->
|
<property name="connectionFactory" ref="connectionFactory"/>
|
||||||
<!--</bean>-->
|
<property name="pubSubDomain" value="false" />
|
||||||
<!--<!– 消费者 –>-->
|
</bean>
|
||||||
<!--<bean id="defaultQueueMessageListener" class="com.zheng.cms.jms.defaultQueueMessageListener"/>-->
|
<bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
|
||||||
<!--<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">-->
|
<property name="connectionFactory" ref="connectionFactory"/>
|
||||||
<!--<property name="connectionFactory" ref="connectionFactory" />-->
|
<property name="pubSubDomain" value="true" />
|
||||||
<!--<property name="destination" ref="defaultQueueDestination" />-->
|
</bean>
|
||||||
<!--<property name="messageListener" ref="defaultQueueMessageListener" />-->
|
|
||||||
<!--</bean>-->
|
<!-- 消费者 -->
|
||||||
|
<bean id="defaultQueueMessageListener" class="com.zheng.cms.jms.defaultQueueMessageListener"/>
|
||||||
|
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||||
|
<property name="connectionFactory" ref="connectionFactory"/>
|
||||||
|
<property name="destination" ref="defaultQueueDestination"/>
|
||||||
|
<property name="messageListener" ref="defaultQueueMessageListener"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
Loading…
Reference in New Issue