Browse Source

Merge remote-tracking branch 'remotes/origin/dev_group_point' into dev_temp

master
jianjun 4 years ago
parent
commit
40b3de1bce
  1. 2
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/RocketMQConsumerRegister.java
  2. 20
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerComponentsListener.java
  3. 68
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerCustomizeListener.java

2
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/RocketMQConsumerRegister.java

@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
//@Component
public class RocketMQConsumerRegister {
@Value("${rocketmq.name-server}")

20
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerComponentsListener.java

@ -1,7 +1,11 @@
package com.epmet.mq.listener;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.commons.rocketmq.register.ConsumerConfigProperties;
import com.epmet.commons.rocketmq.register.MQConsumerRegister;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
@ -15,6 +19,7 @@ import org.apache.rocketmq.common.message.MessageExt;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -22,7 +27,8 @@ import java.util.concurrent.TimeUnit;
/**
* 监听初始化客户动作为客户初始化角色列表
*/
public class InitCustomerComponentsListener implements MessageListenerConcurrently {
@Component
public class InitCustomerComponentsListener extends MQConsumerRegister implements MessageListenerConcurrently {
private Logger logger = LoggerFactory.getLogger(getClass());
@ -65,4 +71,14 @@ public class InitCustomerComponentsListener implements MessageListenerConcurrent
distributedLock.unLock(lock);
}
}
}
@Override
public ConsumerConfigProperties getConsumerProperty() {
ConsumerConfigProperties configProperties = new ConsumerConfigProperties();
configProperties.setConsumerGroup(ConsomerGroupConstants.INIT_CUSTOMER_COMPONENTS_GROUP);
configProperties.setTopic(TopicConstants.INIT_CUSTOMER);
configProperties.setTag("*");
configProperties.setConsumerListener(this);
return configProperties;
}
}

68
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerCustomizeListener.java

@ -1,68 +0,0 @@
package com.epmet.mq.listener;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.dto.CustomerHomeDTO;
import com.epmet.service.CustomerHomeService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* 监听初始化客户动作为客户初始化角色列表
* 已废弃
*/
//@RocketMQMessageListener(topic = TopicConstants.INIT_CUSTOMER,
// consumerGroup = ConsomerGroupConstants.INIT_CUSTOMER_COMPONENTS_GROUP,
// messageModel = MessageModel.CLUSTERING,
// selectorExpression = "*")
//@Component
public class InitCustomerCustomizeListener implements RocketMQListener<MessageExt> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CustomerHomeService customerHomeService;
@Autowired
private DistributedLock distributedLock;
@Override
public void onMessage(MessageExt messageExt) {
String msg = new String(messageExt.getBody());
logger.info("初始化客户-初始化客户自定义信息-收到消息内容:{}", msg);
InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
CustomerHomeDTO customerHomeDTO = new CustomerHomeDTO();
customerHomeDTO.setCustomerId(msgObj.getCustomerId());
RLock lock = null;
try {
lock = distributedLock.getLock(String.format("lock:init_customer_home:%s", msgObj.getCustomerId()),
30l, 30l, TimeUnit.SECONDS);
customerHomeService.init(customerHomeDTO);
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
} catch (Exception e) {
// 不是我们自己抛出的异常,可以让MQ重试
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
throw e;
} finally {
distributedLock.unLock(lock);
}
}
}
Loading…
Cancel
Save