Commit 9ad206cc by lili

topic 修改

parent 63694a3e
......@@ -4,12 +4,9 @@ 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;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -74,14 +71,6 @@ public class BookApplication {
}
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory(@Value("${mq.brokerURL}") String url) {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(url);
activeMQConnectionFactory.setTrustAllPackages(true);
return activeMQConnectionFactory;
}
@Bean
public Queue deleteVideoQueue(){
return RabbitMQFactory.queueBuilder(MQTopicConumer.DELETE_VIDEO);
}
......@@ -90,7 +79,7 @@ public class BookApplication {
public Binding deleteVideoBind(){
return RabbitMQFactory.bindingExchange(deleteVideoQueue(), MQTopicProducer.DELETE_VIDEO);
}
@Bean
public Queue chooseDefaultChannelQueue(){
return RabbitMQFactory.queueBuilder(MQTopicConumer.CHOOSE_DEFAULT_CHANNEL);
......@@ -101,9 +90,15 @@ public class BookApplication {
return RabbitMQFactory.bindingExchange(chooseDefaultChannelQueue(), MQTopicProducer.CHOOSE_DEFAULT_CHANNEL);
}
//调用超时设置
@Bean
Request.Options feignOptions() {
return new Request.Options(300 * 1000, 300 * 1000);
public Queue registerPartyQueue(){
return RabbitMQFactory.queueBuilder(MQTopicConumer.REGISTER_PARTY);
}
@Bean
public Binding registerPartyBind(){
return RabbitMQFactory.bindingExchange(registerPartyQueue(), MQTopicProducer.REGISTER_PARTY);
}
}
......@@ -55,24 +55,25 @@ public class IsbnConsr {
*/
public Book getBook(String isbn) throws IOException {
LOGGER.info("【外部】根据isbn获取书籍信息,<START>.[isbn]=" + isbn);
/* Book book = null;
try {
String result = getBookInfo4jisu(isbn);
// Book book = null;
// try {
/*String result = getBookInfo4jisu(isbn);
book = setBook4jisu(result, isbn);
if (book == null || book.getIsbn() == null) {
// 调用聚合查询书籍
String juheBook = getBookInfo(isbn);
book = setBook(juheBook, isbn);
}
}*/
//if (book == null || book.getIsbn() == null) {
// 调用阿里查询书籍
String aliBook = getBookInfo4Ali(isbn);
book = setBook4Ali(aliBook, isbn);
// }
} catch (Exception e) {
LOGGER.warn("【外部】根据isbn获取书籍信息,<ERROR>", e);
}
LOGGER.info("【外部】根据isbn获取书籍信息,<END>");*/
// String aliBook = getBookInfo4Ali(isbn);
// book = setBook4Ali(aliBook, isbn);
// // }
// } catch (Exception e) {
// LOGGER.warn("【外部】根据isbn获取书籍信息,<ERROR>", e);
// }
// LOGGER.info("【外部】根据isbn获取书籍信息,<END>");
// return book;
return null;
}
......@@ -82,11 +83,7 @@ public class IsbnConsr {
* @param result
* @param isbn
* @return
* @ @throws
* JsonMappingException
* @throws JsonParseException
*/
@SuppressWarnings("unchecked")
private Book setBook4Ali(String result, String isbn) {
Map<String, Object> temp = JSONObject.parseObject(result);
Book book = new Book();
......@@ -118,9 +115,6 @@ public class IsbnConsr {
* @param result
* @param isbn
* @return
* @ @throws
* JsonMappingException
* @throws JsonParseException
*/
@SuppressWarnings("unchecked")
private Book setBook4jisu(String result, String isbn) {
......@@ -155,7 +149,7 @@ public class IsbnConsr {
/**
* 修改图片地址
*
* @param string
* @param picUrl
* @return
*/
private String changePic(String picUrl) {
......
......@@ -6,12 +6,12 @@ package com.pcloud.book.consumer.message;
import java.util.Date;
import java.util.Map;
import com.pcloud.book.base.exception.BookBizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.pcloud.appcenter.base.exception.AppBizException;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.dto.SendMessageDto;
import com.pcloud.common.core.dto.SendNotifyDto;
......@@ -40,7 +40,7 @@ public class MessageConsr {
public void sendLetter(Long fromId, Long toId, String content, String sysCode, String typeCode, String resourceId, String fileName)
throws BizException {
LOGGER.info("【站内信-消息(消)】发送站内信,<START>.[fromId]=" + fromId + ",[toId]=" + toId + ",[content]=" + content
+ ",[sysCode]=" + sysCode + ",[typeCode]=" + typeCode + ",[resourceId]=" + resourceId+"[fileName]="+fileName);
+ ",[sysCode]=" + sysCode + ",[typeCode]=" + typeCode + ",[resourceId]=" + resourceId+ ",fileName="+fileName);
if (fromId == null || toId == null || StringUtil.isEmpty(content) || StringUtil.isEmpty(sysCode)
|| StringUtil.isEmpty(typeCode) || resourceId == null) {
return;
......@@ -63,27 +63,4 @@ public class MessageConsr {
LOGGER.info("【站内信(消)】发送站内信,<END>");
}
/**
* 发送手机消息
*/
public void sendSMS(String phone,Map<String, String> paramMap, String templateCode) throws BizException {
LOGGER.info("【短信消息(消)】发送手机消息.<START>.[phone]=" + phone);
if (StringUtil.isEmpty(phone)) {
throw new AppBizException(AppBizException.PARAM_IS_NULL, "手机消息参数为空");
}
// 组装参数
SendMessageDto smsParam = new SendMessageDto();
smsParam.setSmsTemplateCode(templateCode);
smsParam.setParamKeyMap(paramMap);
smsParam.setPhoneNumber(phone);
try {
messageBiz.sendSMS(smsParam);
} catch (Exception e) {
LOGGER.error("【短信消息(消)】发送手机消息.[sendSMS]:" + e.getMessage(), e);
throw new AppBizException(AppBizException.INVOKE_MESSAGE_ERROR, "发送手机消息失败");
}
LOGGER.info("【短信消息(消)】发送手机消息.<END>");
}
}
......@@ -3,19 +3,18 @@
*/
package com.pcloud.book.consumer.user;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.pcloud.channelcenter.base.exceptions.ChannelBizException;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.usercenter.party.channel.service.ChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @描述:渠道用户中间类
......
......@@ -18,8 +18,7 @@ public class MQTopicConumer {
/**
* 注册当事人Topic监听
*/
//public static final String REGISTER_PARTY = PREFIX + MQTopicProducer.REGISTER_PARTY;
public static final String REGISTER_PARTY = PREFIX + MQTopicProducer.REGISTER_PARTY;
/**
* 选择默认运营
......
/**
*
*/
package com.pcloud.book.mq.config;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.mq.topic.ChooseDefaultChannelListener;
import com.pcloud.book.mq.topic.RegisterPartyListener;
import com.pcloud.book.mq.topic.DeleteVideoListener;
import com.pcloud.book.util.properties.BookProps;
import com.pcloud.common.exceptions.BizException;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import javax.jms.*;
import java.io.Serializable;
/**
* @描述:
*
* @作者:songx
* @创建时间:2017年2月13日,上午11:28:54 @版本:1.0
*/
@Component("mqConfig")
public class MqConfig implements ApplicationListener<ContextRefreshedEvent> {
/**
*
*/
private final static Logger LOGGER = LoggerFactory.getLogger(MqConfig.class);
private static Session session; // 消息上下文
@Autowired
private ActiveMQConnectionFactory connectionFactory;
private static MessageProducer bookDeleteMsgProducer; // 书籍删除消息生产者
@Autowired
private RegisterPartyListener registerPartyListener; // 注册当事人Topic监听
private static MessageProducer bookThawProducer; // 书籍解冻消息生产者
private Boolean bool = false;
/**
* 初始化
*/
@Override
public void onApplicationEvent(ContextRefreshedEvent arg0) {
if (!bool && arg0.getSource() instanceof AnnotationConfigEmbeddedWebApplicationContext) {
LOGGER.info("【消息队列】初始化消息发送队列,<START>");
bool = true;
try {
ActiveMQConnection conn = (ActiveMQConnection) connectionFactory.createConnection();
conn.start();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
} catch (Exception e) {
LOGGER.error("【消息队列】初始化消息发送队列,<ERROR>:" + e.getMessage(), e);
throw new BookBizException(BookBizException.SEND_TOPIC_ERROR, "初始化消息发送队列失败");
}
// 创建生产者
bookDeleteMsgProducer = this.createProducer(BookProps.getBookDeleteProducer());
bookThawProducer = this.createProducer(BookProps.getBookThawProducer());
// 创建消费者,开始监听
// this.createConsumer(deleteVideoListener, BookProps.getDeleteVideoConsumer());
this.createConsumer(registerPartyListener, BookProps.getRegisterPartyConsumer());
LOGGER.info("【消息队列】初始化消息发送队列,<END>");
}
}
/**
* 创建生产者
*/
private MessageProducer createProducer(String producerName) throws BizException {
try {
return session.createProducer(new ActiveMQTopic(producerName));
} catch (Exception e) {
LOGGER.error("【消息队列】初始化生产者Topic,<ERROR>.[" + producerName + "]:" + e.getMessage(), e);
}
return null;
}
/**
* 创建消费者监听
*/
private void createConsumer(MessageListener messageListener, String consumerName) throws BizException {
try {
Queue queue = new ActiveMQQueue(consumerName);
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(messageListener);
} catch (Exception e) {
LOGGER.error("【消息队列】初始化消费者监听,<ERROR>.[" + consumerName + "]:" + e.getMessage(), e);
}
}
/**
* 发送书籍删除Topic
*
* @param object
*/
public static void sendBookDeleteTopic(Serializable object) throws BizException {
sendMsg(bookDeleteMsgProducer, object, BookProps.getBookDeleteProducer());
}
/**
* 发送图书解冻Topic
*
* @param object
*/
public static void sendBookThawTopic(Serializable object) throws BizException {
sendMsg(bookThawProducer, object, BookProps.getBookThawProducer());
}
/**
* 发送消息
*
* @param producer
* @param object
*/
private static void sendMsg(MessageProducer producer, Serializable object, String producerName)
throws BizException {
LOGGER.info("【消息队列】发送Topic消息,<START>.[producerName]=" + producerName);
try {
ObjectMessage message = session.createObjectMessage(object);
producer.send(message);
} catch (Exception e) {
LOGGER.error("【消息队列】发送Topic消息[" + producerName + "],<ERROR>:" + e.getMessage(), e);
}
LOGGER.info("【消息队列】发送Topic消息,<END>");
}
}
package com.pcloud.book.mq.topic;
import com.pcloud.book.book.biz.BookAdviserBiz;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
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;
......@@ -13,6 +14,11 @@ 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;
/**
* @描述: 选择默认渠道
*/
......
......@@ -4,9 +4,13 @@ import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.usercenter.common.enums.ResourceEnum;
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;
......@@ -16,34 +20,22 @@ import com.pcloud.common.core.constant.SystemCode;
import com.pcloud.usercenter.party.common.entity.Party;
@Component("registerPartyListener")
public class RegisterPartyListener implements MessageListener {
@RabbitListener(queues = MQTopicConumer.REGISTER_PARTY)
public class RegisterPartyListener{
@Autowired
private BookAdviserBiz bookAdviserBiz;
private static final Logger LOGGER = LoggerFactory.getLogger(RegisterPartyListener.class);
/**
* 用户注册Topic
*/
@Override
public void onMessage(Message message) {
if (!(message instanceof ObjectMessage)) {
throw new AppBizException(AppBizException.CONSUMER_TOPIC_ERROR, "【注册用户】类型转换错误");
}
// 转换消息实体
Party party = null;
try {
ObjectMessage om = (ObjectMessage) message;
party = (Party) om.getObject();
} catch (Exception e) {
LOGGER.error("【注册用户】消费topic,<ERROR>:" + e.getMessage(), e);
return;
}
@ParamLog("用户注册topic")
@RabbitHandler
public void process(Party party) {
if (party == null) {
return;
}
if (SystemCode.adviser.code.equalsIgnoreCase(party.getPartyRole()) && ResourceEnum.APP.code.equals(party.getResourceId())) {
bookAdviserBiz.createDefaultBook(party.getAgentId(), party.getId());
}
}
}
......@@ -34,48 +34,6 @@ public class BookProps {
*/
private static String jisuAppKey;
/**
* 书籍删除
*/
private static String bookDeleteProducer;
/**
* 录音删除
*/
private static String deleteVideoConsumer;
/**
* 用户注册
*/
private static String registerPartyConsumer;
/**
* 默认运营选择
*/
private static String chooseDefaultChannelConsumer;
/**
* 图书解冻
*/
private static String bookThawProducer;
public static String getBookThawProducer() {
return bookThawProducer;
}
@Value("${book.thaw.producer}")
public void setBookThawProducer(String bookThawProducer) {
BookProps.bookThawProducer = bookThawProducer;
}
public static String getBookDeleteProducer() {
return bookDeleteProducer;
}
@Value("${book.delete.producer}")
public void setBookDeleteProducer(String bookDeleteProducer) {
BookProps.bookDeleteProducer = bookDeleteProducer;
}
public static String getJisuAppKey() {
return jisuAppKey;
}
......@@ -111,30 +69,4 @@ public class BookProps {
public void setAppCode(String appCode) {
BookProps.appCode = appCode;
}
public static String getDeleteVideoConsumer() {
return deleteVideoConsumer;
}
@Value("${delete.video.consumer}")
public void setDeleteVideoConsumer(String deleteVideoConsumer) {
BookProps.deleteVideoConsumer = deleteVideoConsumer;
}
@Value("${register.party.consumer}")
public void setRegisterPartyConsumer(String registerPartyConsumer) {
BookProps.registerPartyConsumer = registerPartyConsumer;
}
public static String getRegisterPartyConsumer() {
return registerPartyConsumer;
}
public static String getChooseDefaultChannelConsumer() {
return chooseDefaultChannelConsumer;
}
@Value("${choose.default.channel.consumer}")
public void setChooseDefaultChannelConsumer(String chooseDefaultChannelConsumer) {
BookProps.chooseDefaultChannelConsumer = chooseDefaultChannelConsumer;
}
}
# \u4e66\u7c4d\u5220\u9664topic
book.delete.producer = VirtualTopic.BOOKDELETE
# \u5f55\u97f3\u5220\u9664topic
delete.video.consumer = Consumer.BOOK.VirtualTopic.DELETEVIDEO
# bookUrl
book.cover.img = http://file.5rs.me/group1/M00/00/94/Ch7HtljQxEuASX6kAACvt6pHb2s229.jpg
......@@ -15,11 +9,3 @@ isbn.appCode = 26ddebd7827448b798bdc6c4738be0ff
# isbn\u5bc6\u94a5
isbn.jisu.appkey = 37c80a8116e3349e
# \u5f53\u4e8b\u4eba\u6ce8\u518c
register.party.consumer = Consumer.BOOK.VirtualTopic.REGISTERPARTY
book.thaw.producer = VirtualTopic.BOOKTHAW
#\u9ED8\u8BA4\u8FD0\u8425\u9009\u62E9
choose.default.channel.consumer = Consumer.BOOK.VirtualTopic.chooseDefaultChannel
\ No newline at end of file
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