12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package com.yihu.wlyy.config;
- import com.yihu.wlyy.activemq.HealthArtListener;
- import com.yihu.wlyy.util.SpringUtil;
- import org.apache.activemq.ActiveMQConnectionFactory;
- import org.apache.activemq.ActiveMQSession;
- import org.apache.activemq.command.ActiveMQQueue;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.context.annotation.Primary;
- import org.springframework.jms.annotation.EnableJms;
- import org.springframework.jms.connection.CachingConnectionFactory;
- import org.springframework.jms.core.JmsTemplate;
- import org.springframework.jms.listener.DefaultMessageListenerContainer;
- import javax.annotation.PostConstruct;
- import javax.jms.MessageListener;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * Created by chenweida on 2017/9/9.
- * 生产者配置
- */
- @EnableJms
- @Configuration
- public class ActiveMQConfig {
- @Value("${activemq.username}")
- private String username;
- @Value("${activemq.password}")
- private String password;
- @Value("${activemq.url}")
- private String url;
- @Bean
- public ActiveMQConnectionFactory activeMQConnectionFactory() {
- ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(username, password, url);
- //设置异步发送
- activeMQConnectionFactory.setUseAsyncSend(true);
- return activeMQConnectionFactory;
- }
- /**
- * 缓存session链接
- *
- * @return
- */
- @Bean
- @Primary
- public CachingConnectionFactory CachingConnectionFactory() {
- CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
- //目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory
- cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory());
- //Session缓存数量,这里属性也可以直接在这里配置
- cachingConnectionFactory.setSessionCacheSize(100);
- return cachingConnectionFactory;
- }
- @Bean
- public JmsTemplate jmsTemplate() {
- JmsTemplate jmsTemplate = new JmsTemplate();
- jmsTemplate.setConnectionFactory(CachingConnectionFactory());
- return jmsTemplate;
- }
- }
|