|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants; |
|
|
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants; |
|
|
import com.epmet.commons.rocketmq.constants.TopicConstants; |
|
|
import com.epmet.commons.rocketmq.constants.TopicConstants; |
|
|
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg; |
|
|
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.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.dto.CustomerHomeDTO; |
|
|
import com.epmet.dto.CustomerHomeDTO; |
|
@ -12,11 +13,14 @@ import org.apache.rocketmq.common.message.MessageExt; |
|
|
import org.apache.rocketmq.spring.annotation.MessageModel; |
|
|
import org.apache.rocketmq.spring.annotation.MessageModel; |
|
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
|
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
|
|
import org.apache.rocketmq.spring.core.RocketMQListener; |
|
|
import org.apache.rocketmq.spring.core.RocketMQListener; |
|
|
|
|
|
import org.redisson.api.RLock; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 监听初始化客户动作,为客户初始化角色列表 |
|
|
* 监听初始化客户动作,为客户初始化角色列表 |
|
|
*/ |
|
|
*/ |
|
@ -32,6 +36,9 @@ public class InitCustomerCustomizeListener implements RocketMQListener<MessageEx |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerHomeService customerHomeService; |
|
|
private CustomerHomeService customerHomeService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DistributedLock distributedLock; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onMessage(MessageExt messageExt) { |
|
|
public void onMessage(MessageExt messageExt) { |
|
|
String msg = new String(messageExt.getBody()); |
|
|
String msg = new String(messageExt.getBody()); |
|
@ -40,7 +47,11 @@ public class InitCustomerCustomizeListener implements RocketMQListener<MessageEx |
|
|
|
|
|
|
|
|
CustomerHomeDTO customerHomeDTO = new CustomerHomeDTO(); |
|
|
CustomerHomeDTO customerHomeDTO = new CustomerHomeDTO(); |
|
|
customerHomeDTO.setCustomerId(msgObj.getCustomerId()); |
|
|
customerHomeDTO.setCustomerId(msgObj.getCustomerId()); |
|
|
|
|
|
|
|
|
|
|
|
RLock lock = null; |
|
|
try { |
|
|
try { |
|
|
|
|
|
lock = distributedLock.getLock(String.format("lock:init_customer_home:%s", msgObj.getCustomerId()), |
|
|
|
|
|
30l, 30l, TimeUnit.SECONDS); |
|
|
customerHomeService.init(customerHomeDTO); |
|
|
customerHomeService.init(customerHomeDTO); |
|
|
} catch (RenException e) { |
|
|
} catch (RenException e) { |
|
|
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
|
|
|
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
|
|
@ -48,7 +59,9 @@ public class InitCustomerCustomizeListener implements RocketMQListener<MessageEx |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
// 不是我们自己抛出的异常,可以让MQ重试
|
|
|
// 不是我们自己抛出的异常,可以让MQ重试
|
|
|
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e))); |
|
|
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e))); |
|
|
throw e; |
|
|
throw e; |
|
|
|
|
|
} finally { |
|
|
|
|
|
distributedLock.unLock(lock); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |