use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.
the class TpcMqMessageServiceImpl method saveAndSendMessage.
@Override
public void saveAndSendMessage(TpcMqMessageDto tpcMqMessageDto) {
if (StringUtils.isEmpty(tpcMqMessageDto.getMessageTopic())) {
throw new TpcBizException(ErrorCodeEnum.TPC10050001);
}
Date now = new Date();
TpcMqMessage message = new ModelMapper().map(tpcMqMessageDto, TpcMqMessage.class);
message.setMessageStatus(MqSendStatusEnum.SENDING.sendStatus());
message.setId(generateId());
message.setUpdateTime(now);
message.setCreatedTime(now);
tpcMqMessageMapper.insertSelective(message);
// 创建消费待确认列表
this.createMqConfirmListByTopic(message.getMessageTopic(), message.getId(), message.getMessageKey());
this.directSendMessage(tpcMqMessageDto.getMessageBody(), tpcMqMessageDto.getMessageTopic(), tpcMqMessageDto.getMessageTag(), tpcMqMessageDto.getMessageKey(), tpcMqMessageDto.getProducerGroup(), tpcMqMessageDto.getDelayLevel());
}
use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.
the class TpcMqMessageServiceImpl method setMessageToAlreadyDead.
@Override
public void setMessageToAlreadyDead(Long messageId) {
final TpcMqMessage task = tpcMqMessageMapper.selectByPrimaryKey(messageId);
if (task == null) {
throw new TpcBizException(ErrorCodeEnum.TPC10050006);
}
tpcMqMessageMapper.updateAlreadyDeadByMessageId(messageId);
}
use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.
the class TpcMqMessageServiceImpl method saveMessageWaitingConfirm.
@Override
public void saveMessageWaitingConfirm(TpcMqMessageDto messageDto) {
if (StringUtils.isEmpty(messageDto.getMessageTopic())) {
throw new TpcBizException(ErrorCodeEnum.TPC10050001);
}
Date now = new Date();
TpcMqMessage message = new ModelMapper().map(messageDto, TpcMqMessage.class);
message.setMessageStatus(MqSendStatusEnum.WAIT_SEND.sendStatus());
message.setUpdateTime(now);
message.setCreatedTime(now);
tpcMqMessageMapper.insertSelective(message);
}
use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.
the class MqConsumerStoreAspect method processMqConsumerStoreJoinPoint.
/**
* Add exe time method object.
*
* @param joinPoint the join point
*
* @return the object
*
* @throws Throwable the throwable
*/
@Around(value = "mqConsumerStoreAnnotationPointcut()")
public Object processMqConsumerStoreJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("processMqConsumerStoreJoinPoint - 线程id={}", Thread.currentThread().getId());
Object result;
long startTime = System.currentTimeMillis();
Object[] args = joinPoint.getArgs();
MqConsumerStore annotation = getAnnotation(joinPoint);
boolean isStorePreStatus = annotation.storePreStatus();
List<MessageExt> messageExtList;
if (args == null || args.length == 0) {
throw new TpcBizException(ErrorCodeEnum.TPC10050005);
}
if (!(args[0] instanceof List)) {
throw new TpcBizException(ErrorCodeEnum.GL99990001);
}
try {
messageExtList = (List<MessageExt>) args[0];
} catch (Exception e) {
log.error("processMqConsumerStoreJoinPoint={}", e.getMessage(), e);
throw new TpcBizException(ErrorCodeEnum.GL99990001);
}
MqMessageData dto = this.getTpcMqMessageDto(messageExtList.get(0));
final String messageKey = dto.getMessageKey();
if (isStorePreStatus) {
mqMessageService.confirmReceiveMessage(consumerGroup, dto);
}
String methodName = joinPoint.getSignature().getName();
try {
result = joinPoint.proceed();
log.info("result={}", result);
if (CONSUME_SUCCESS.equals(result.toString())) {
mqMessageService.saveAndConfirmFinishMessage(consumerGroup, messageKey);
}
} catch (Exception e) {
log.error("发送可靠消息, 目标方法[{}], 出现异常={}", methodName, e.getMessage(), e);
throw e;
} finally {
log.info("发送可靠消息 目标方法[{}], 总耗时={}", methodName, System.currentTimeMillis() - startTime);
}
return result;
}
use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.
the class MqMessageServiceImpl method confirmReceiveMessage.
@Override
@Transactional(rollbackFor = Exception.class)
public void confirmReceiveMessage(String cid, MqMessageData messageData) {
final String messageKey = messageData.getMessageKey();
log.info("confirmReceiveMessage - 消费者={}, 确认收到key={}的消息", cid, messageKey);
// 先保存消息
messageData.setMessageType(MqMessageTypeEnum.CONSUMER_MESSAGE.messageType());
messageData.setId(UniqueIdGenerator.generateId());
mqMessageDataMapper.insertSelective(messageData);
Wrapper wrapper = tpcMqMessageFeignApi.confirmReceiveMessage(cid, messageKey);
log.info("tpcMqMessageFeignApi.confirmReceiveMessage result={}", wrapper);
if (wrapper == null) {
throw new TpcBizException(ErrorCodeEnum.GL99990002);
}
if (wrapper.error()) {
throw new TpcBizException(ErrorCodeEnum.TPC10050004, wrapper.getMessage(), messageKey);
}
}
Aggregations