Commit 3297fab6 by lili

deleteVideo Topic 合并

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