Search in sources :

Example 6 with TpcBizException

use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.

the class MqMessageServiceImpl method saveAndConfirmFinishMessage.

@Override
public void saveAndConfirmFinishMessage(String cid, String messageKey) {
    Wrapper wrapper = tpcMqMessageFeignApi.confirmConsumedMessage(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)

Example 7 with TpcBizException

use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.

the class MqMessageServiceImpl method confirmAndSendMessage.

@Override
public void confirmAndSendMessage(String messageKey) {
    // 发送确认消息给消息中心
    try {
        Wrapper wrapper = tpcMqMessageFeignApi.confirmAndSendMessage(messageKey);
        if (wrapper == null) {
            throw new TpcBizException(ErrorCodeEnum.GL99990002);
        }
        if (wrapper.error()) {
            throw new TpcBizException(ErrorCodeEnum.TPC10050004, wrapper.getMessage(), messageKey);
        }
        log.info("<== saveMqProducerMessage - 存储并发送消息给消息中心成功. messageKey={}", messageKey);
    } catch (Exception e) {
        log.error("<== saveMqProducerMessage - 存储并发送消息给消息中心失败. messageKey={}", messageKey, e);
    }
}
Also used : Wrapper(com.paascloud.wrapper.Wrapper) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) TpcBizException(com.paascloud.provider.exceptions.TpcBizException)

Example 8 with TpcBizException

use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.

the class MqProducerStoreAspect method processMqProducerStoreJoinPoint.

/**
 * Add exe time method object.
 *
 * @param joinPoint the join point
 *
 * @return the object
 */
@Around(value = "mqProducerStoreAnnotationPointcut()")
public Object processMqProducerStoreJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
    log.info("processMqProducerStoreJoinPoint - 线程id={}", Thread.currentThread().getId());
    Object result;
    Object[] args = joinPoint.getArgs();
    MqProducerStore annotation = getAnnotation(joinPoint);
    MqSendTypeEnum type = annotation.sendType();
    int orderType = annotation.orderType().orderType();
    DelayLevelEnum delayLevelEnum = annotation.delayLevel();
    if (args.length == 0) {
        throw new TpcBizException(ErrorCodeEnum.TPC10050005);
    }
    MqMessageData domain = null;
    for (Object object : args) {
        if (object instanceof MqMessageData) {
            domain = (MqMessageData) object;
            break;
        }
    }
    if (domain == null) {
        throw new TpcBizException(ErrorCodeEnum.TPC10050005);
    }
    domain.setOrderType(orderType);
    domain.setProducerGroup(producerGroup);
    if (type == MqSendTypeEnum.WAIT_CONFIRM) {
        if (delayLevelEnum != DelayLevelEnum.ZERO) {
            domain.setDelayLevel(delayLevelEnum.delayLevel());
        }
        mqMessageService.saveWaitConfirmMessage(domain);
    }
    result = joinPoint.proceed();
    if (type == MqSendTypeEnum.SAVE_AND_SEND) {
        mqMessageService.saveAndSendMessage(domain);
    } else if (type == MqSendTypeEnum.DIRECT_SEND) {
        mqMessageService.directSendMessage(domain);
    } else {
        mqMessageService.confirmAndSendMessage(domain.getMessageKey());
    }
    return result;
}
Also used : MqProducerStore(com.paascloud.provider.annotation.MqProducerStore) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) MqSendTypeEnum(com.paascloud.provider.model.enums.MqSendTypeEnum) DelayLevelEnum(com.paascloud.provider.model.enums.DelayLevelEnum) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 9 with TpcBizException

use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.

the class RocketMqProducer method sendSimpleMessage.

public static SendResult sendSimpleMessage(String body, String topic, String tag, String key, String pid, Integer delayLevel) {
    if (delayLevel == null) {
        delayLevel = 0;
    }
    Message message = MqMessage.checkMessage(body, topic, tag, key);
    if (delayLevel < 0 || delayLevel > GlobalConstant.Number.EIGHTEEN_INT) {
        throw new TpcBizException(ErrorCodeEnum.TPC100500013, topic, key);
    }
    message.setDelayTimeLevel(delayLevel);
    return retrySendMessage(pid, message);
}
Also used : Message(org.apache.rocketmq.common.message.Message) MqMessage(com.paascloud.core.mq.MqMessage) TpcBizException(com.paascloud.provider.exceptions.TpcBizException)

Example 10 with TpcBizException

use of com.paascloud.provider.exceptions.TpcBizException in project paascloud-master by paascloud.

the class RocketMqProducer method retrySendMessage.

private static SendResult retrySendMessage(String pid, Message msg) {
    int iniCount = 1;
    SendResult result;
    while (true) {
        try {
            result = MqProducerBeanFactory.getBean(pid).send(msg);
            break;
        } catch (Exception e) {
            log.error("发送消息失败:", e);
            if (iniCount++ >= PRODUCER_RETRY_TIMES) {
                throw new TpcBizException(ErrorCodeEnum.TPC100500014, msg.getTopic(), msg.getKeys());
            }
        }
    }
    log.info("<== 发送MQ SendResult={}", result);
    return result;
}
Also used : SendResult(org.apache.rocketmq.client.producer.SendResult) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) TpcBizException(com.paascloud.provider.exceptions.TpcBizException)

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