Commit 3a12cd37 by lili

mq 修改

parent 7a5bb907
package com.pcloud.book;
import java.util.ArrayList;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.constant.MQTopicProducer;
import com.pcloud.common.core.mq.RabbitMQFactory;
import feign.Request;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
......@@ -17,10 +20,6 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import com.alibaba.druid.pool.DruidDataSource;
import feign.Request;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
......@@ -29,6 +28,9 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import javax.sql.DataSource;
import java.util.ArrayList;
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("com.pcloud")
......@@ -77,48 +79,18 @@ public class BookApplication {
activeMQConnectionFactory.setTrustAllPackages(true);
return activeMQConnectionFactory;
}
// @Bean
// @Autowired
// public CachingConnectionFactory catchingConnectionFactory(ActiveMQConnectionFactory activeMQConnectionFactory){
// CachingConnectionFactory catchingConnectionFactory = new CachingConnectionFactory(activeMQConnectionFactory);
// return catchingConnectionFactory;
// }
/*@Bean
@Autowired
public ActiveMQQueue activeMQQueue(CachingConnectionFactory catchingConnectionFactory){
ActiveMQQueue templateQueue = new ActiveMQQueue("template");
return templateQueue;
}
@Bean
public JmsTemplate jmsTemplate(@Autowired CachingConnectionFactory catchingConnectionFactory, @Autowired ActiveMQQueue templateQueue){
JmsTemplate jmsTemplateTemplate = new JmsTemplate();
jmsTemplateTemplate.setDefaultDestination(templateQueue);
jmsTemplateTemplate.setConnectionFactory(catchingConnectionFactory);
jmsTemplateTemplate.setReceiveTimeout(10000);
return jmsTemplateTemplate;
}*/
/*
@Bean
public TemplateMessageListener templateMessageListener(){
TemplateMessageListener templateMessageListener = new TemplateMessageListener();
return templateMessageListener;
public Queue chooseDefaultChannelQueue(){
return RabbitMQFactory.queueBuilder(MQTopicConumer.CHOOSE_DEFAULT_CHANNEL);
}
@Bean
public DefaultMessageListenerContainer messageListenerContainer(@Autowired CachingConnectionFactory catchingConnectionFactory, @Autowired ActiveMQQueue templateQueue, @Autowired TemplateMessageListener templateMessageListener){
DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
messageListenerContainer.setConnectionFactory(catchingConnectionFactory);
messageListenerContainer.setMessageListener(templateMessageListener);
messageListenerContainer.setDestination(templateQueue);
messageListenerContainer.setSessionTransacted(true);
messageListenerContainer.setConcurrency("1");
return messageListenerContainer;
public Binding chooseDefaultChannelBind(){
return RabbitMQFactory.bindingExchange(chooseDefaultChannelQueue(), MQTopicProducer.CHOOSE_DEFAULT_CHANNEL);
}
*/
//调用超时设置
@Bean
Request.Options feignOptions() {
......
......@@ -51,9 +51,6 @@ public class MqConfig implements ApplicationListener<ContextRefreshedEvent> {
private RegisterPartyListener registerPartyListener; // 注册当事人Topic监听
private static MessageProducer bookThawProducer; // 书籍解冻消息生产者
@Autowired
private ChooseDefaultChannelListener chooseDefaultChannelListener; // 注册当事人Topic监听
private Boolean bool = false;
/**
......@@ -77,7 +74,6 @@ public class MqConfig implements ApplicationListener<ContextRefreshedEvent> {
bookThawProducer = this.createProducer(BookProps.getBookThawProducer());
// 创建消费者,开始监听
this.createConsumer(deleteVideoListener, BookProps.getDeleteVideoConsumer());
this.createConsumer(chooseDefaultChannelListener, BookProps.getChooseDefaultChannelConsumer());
this.createConsumer(registerPartyListener, BookProps.getRegisterPartyConsumer());
LOGGER.info("【消息队列】初始化消息发送队列,<END>");
}
......
package com.pcloud.book.mq.topic;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import com.pcloud.book.book.biz.BookAdviserBiz;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.usercenter.common.enums.ResourceEnum;
import com.pcloud.usercenter.system.entity.ExtraSetting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.biz.BookAdviserBiz;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.usercenter.system.entity.ExtraSetting;
/**
* @描述: 选择默认渠道
*/
@Component("chooseDefaultChannelListener")
public class ChooseDefaultChannelListener implements MessageListener {
@RabbitListener(queues = MQTopicConumer.CHOOSE_DEFAULT_CHANNEL)
public class ChooseDefaultChannelListener{
@Autowired
private BookAdviserBiz bookAdviserBiz;
private static final Logger LOGGER = LoggerFactory.getLogger(ChooseDefaultChannelListener.class);
......@@ -27,20 +26,9 @@ public class ChooseDefaultChannelListener implements MessageListener {
/**
* 选择默认渠道Topic
*/
@Override
public void onMessage(Message message) {
if (!(message instanceof ObjectMessage)) {
throw new BookBizException(BookBizException.CONSUMER_TOPIC_ERROR, "【选择默认渠道】类型转换错误");
}
// 转换消息实体
ExtraSetting extraSetting = null;
try {
ObjectMessage om = (ObjectMessage) message;
extraSetting = (ExtraSetting) om.getObject();
} catch (Exception e) {
LOGGER.error("【选择默认渠道】消费topic,<ERROR>:" + e.getMessage(), e);
return;
}
@RabbitHandler
@ParamLog("选择默认渠道Topic")
public void onMessage(ExtraSetting extraSetting) {
if (extraSetting == null) {
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment