Commit 3297fab6 by lili

deleteVideo Topic 合并

parent 4da6f8d5
......@@ -72,6 +72,7 @@ public class BookApplication {
((DruidDataSource) dataSource).setConnectionInitSqls(arr);
return dataSource;
}
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory(@Value("${mq.brokerURL}") String url) {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
......@@ -80,6 +81,15 @@ public class BookApplication {
return activeMQConnectionFactory;
}
@Bean
public Queue deleteVideoQueue(){
return RabbitMQFactory.queueBuilder(MQTopicConumer.DELETE_VIDEO);
}
@Bean
public Binding deleteVideoBind(){
return RabbitMQFactory.bindingExchange(deleteVideoQueue(), MQTopicProducer.DELETE_VIDEO);
}
@Bean
public Queue chooseDefaultChannelQueue(){
......
......@@ -13,7 +13,7 @@ public class MQTopicConumer {
/**
* 清除录音消费者
*/
//public static final String DELETE_VIDEO = PREFIX + MQTopicProducer.DELETE_VIDEO;
public static final String DELETE_VIDEO = PREFIX + MQTopicProducer.DELETE_VIDEO;
/**
* 注册当事人Topic监听
......
......@@ -42,9 +42,6 @@ public class MqConfig implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private ActiveMQConnectionFactory connectionFactory;
@Autowired
private DeleteVideoListener deleteVideoListener; // 清除录音
private static MessageProducer bookDeleteMsgProducer; // 书籍删除消息生产者
@Autowired
......@@ -73,7 +70,7 @@ public class MqConfig implements ApplicationListener<ContextRefreshedEvent> {
bookDeleteMsgProducer = this.createProducer(BookProps.getBookDeleteProducer());
bookThawProducer = this.createProducer(BookProps.getBookThawProducer());
// 创建消费者,开始监听
this.createConsumer(deleteVideoListener, BookProps.getDeleteVideoConsumer());
// this.createConsumer(deleteVideoListener, BookProps.getDeleteVideoConsumer());
this.createConsumer(registerPartyListener, BookProps.getRegisterPartyConsumer());
LOGGER.info("【消息队列】初始化消息发送队列,<END>");
}
......
......@@ -7,8 +7,11 @@ import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import com.pcloud.book.mq.config.MQTopicConumer;
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;
......@@ -22,8 +25,9 @@ import com.pcloud.common.exceptions.BizException;
* @作者:songx
* @创建时间:2017年7月5日,上午11:58:44 @版本:1.0
*/
@Component("deleteVideoListener")
public class DeleteVideoListener implements MessageListener {
@Component
@RabbitListener(queues = MQTopicConumer.DELETE_VIDEO)
public class DeleteVideoListener {
/**
*
......@@ -36,21 +40,15 @@ public class DeleteVideoListener implements MessageListener {
/**
* 接收录音删除消息
*/
@Override
public void onMessage(Message message) throws BizException {
if (!(message instanceof ObjectMessage)) {
throw new BookBizException(BookBizException.CONSUMER_TOPIC_ERROR, "【录音删除】类型转换错误");
}
try {
// 转换消息实体
ObjectMessage om = (ObjectMessage) message;
Long videoId = Long.parseLong(om.getObject().toString());
@RabbitHandler
public void process(Long videoId) throws BizException {
if (videoId == null) return;
try{
// 清除录音
bookProductBiz.clearSound(videoId);
} catch (Exception e) {
LOGGER.error("【录音删除】消费topic,JMS异常,<ERROR>:" + e.getMessage(), e);
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