Search in sources :

Example 1 with TpcBizException

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());
}
Also used : TpcMqMessage(com.paascloud.provider.model.domain.TpcMqMessage) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) Date(java.util.Date) ModelMapper(org.modelmapper.ModelMapper)

Example 2 with TpcBizException

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);
}
Also used : TpcMqMessage(com.paascloud.provider.model.domain.TpcMqMessage) TpcBizException(com.paascloud.provider.exceptions.TpcBizException)

Example 3 with TpcBizException

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);
}
Also used : TpcMqMessage(com.paascloud.provider.model.domain.TpcMqMessage) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) Date(java.util.Date) ModelMapper(org.modelmapper.ModelMapper)

Example 4 with TpcBizException

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;
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) MqConsumerStore(com.paascloud.provider.annotation.MqConsumerStore) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) List(java.util.List) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) Around(org.aspectj.lang.annotation.Around)

Example 5 with TpcBizException

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);
    }
}
Also used : Wrapper(com.paascloud.wrapper.Wrapper) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TpcBizException (com.paascloud.provider.exceptions.TpcBizException)13 TpcMqMessage (com.paascloud.provider.model.domain.TpcMqMessage)5 Wrapper (com.paascloud.wrapper.Wrapper)3 Date (java.util.Date)3 MqMessageData (com.paascloud.provider.model.domain.MqMessageData)2 Around (org.aspectj.lang.annotation.Around)2 ModelMapper (org.modelmapper.ModelMapper)2 MqMessage (com.paascloud.core.mq.MqMessage)1 MqConsumerStore (com.paascloud.provider.annotation.MqConsumerStore)1 MqProducerStore (com.paascloud.provider.annotation.MqProducerStore)1 TpcMqConfirm (com.paascloud.provider.model.domain.TpcMqConfirm)1 DelayLevelEnum (com.paascloud.provider.model.enums.DelayLevelEnum)1 MqSendTypeEnum (com.paascloud.provider.model.enums.MqSendTypeEnum)1 List (java.util.List)1 SendResult (org.apache.rocketmq.client.producer.SendResult)1 Message (org.apache.rocketmq.common.message.Message)1 MessageExt (org.apache.rocketmq.common.message.MessageExt)1 JoinPoint (org.aspectj.lang.JoinPoint)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Transactional (org.springframework.transaction.annotation.Transactional)1