使用useAsyncSend异步发送消息
This commit is contained in:
parent
41055caba1
commit
963abaef61
|
@ -11,7 +11,7 @@
|
|||
</bean>
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory" ref="activeMqConnectionFactory"/>
|
||||
<!--<property name="sessionCacheSize" value="100"/>-->
|
||||
<property name="sessionCacheSize" value="100"/>
|
||||
</bean>
|
||||
<!-- 点对点队列 -->
|
||||
<bean id="defaultQueueDestination" class="org.apache.activemq.command.ActiveMQQueue">
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
@ -29,21 +28,13 @@ public class ActiveMQController extends BaseController {
|
|||
@Autowired
|
||||
Destination defaultQueueDestination;
|
||||
|
||||
@Autowired
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
@RequestMapping("/send")
|
||||
@ResponseBody
|
||||
public Object send() {
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100; i ++) {
|
||||
_log.info("发送消息" + (i + 1));
|
||||
final long time = System.currentTimeMillis();
|
||||
threadPoolTaskExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
JmsUtil.sendMessage(jmsQueueTemplate, defaultQueueDestination, "消息" + time);
|
||||
}
|
||||
});
|
||||
JmsUtil.sendMessage(jmsQueueTemplate, defaultQueueDestination, "消息" + (i + 1));
|
||||
}
|
||||
_log.info("发送消息消耗时间" + (System.currentTimeMillis() - start));
|
||||
return "success";
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<!-- 连接工厂 -->
|
||||
<bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="${AvtiveMQ.brokerURL}"/>
|
||||
<property name="useAsyncSend" value="true"/>
|
||||
</bean>
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory" ref="activeMqConnectionFactory"/>
|
||||
|
|
Loading…
Reference in New Issue