Search in sources :

Example 1 with MqMessageData

use of com.paascloud.provider.model.domain.MqMessageData in project paascloud-master by paascloud.

the class SmsProducer method sendSmsCodeMq.

public MqMessageData sendSmsCodeMq(SmsMessage smsMessage, AliyunSmsConstants.SmsTempletEnum templetEnum) {
    log.info("sendSmsCodeMq - 发送短信验证码. smsMessage={}", smsMessage);
    String msgBody;
    try {
        PcSendSmsRequest request = new PcSendSmsRequest();
        Map<String, String> map = Maps.newHashMap();
        // 模板参数
        String smsParamName = templetEnum.getSmsParamName();
        // 模板编码
        String templetCode = templetEnum.getTempletCode();
        // 替换模板验证码
        map.put(smsParamName, smsMessage.getSmsCode());
        String param = JSON.toJSONString(map);
        request.setPhoneNumbers(smsMessage.getMobileNo());
        request.setTemplateCode(templetCode);
        request.setTemplateParam(param);
        request.setOutId(smsMessage.getOutId());
        msgBody = JSON.toJSONString(request);
    } catch (Exception e) {
        log.error("发送短信验证码 smsMessage转换为json字符串失败", e);
        throw new UacBizException(ErrorCodeEnum.UAC10011022);
    }
    String topic = AliyunMqTopicConstants.MqTopicEnum.SEND_SMS_TOPIC.getTopic();
    String tag = AliyunMqTopicConstants.MqTagEnum.REGISTER_USER_AUTH_CODE.getTag();
    String key = RedisKeyUtil.createMqKey(topic, tag, smsMessage.getMobileNo(), msgBody);
    return new MqMessageData(msgBody, topic, tag, key);
}
Also used : PcSendSmsRequest(com.paascloud.provider.model.dto.PcSendSmsRequest) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) UacBizException(com.paascloud.provider.model.exceptions.UacBizException)

Example 2 with MqMessageData

use of com.paascloud.provider.model.domain.MqMessageData 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 3 with MqMessageData

use of com.paascloud.provider.model.domain.MqMessageData in project paascloud-master by paascloud.

the class MqConsumerStoreAspect method getTpcMqMessageDto.

private MqMessageData getTpcMqMessageDto(MessageExt messageExt) {
    MqMessageData data = new MqMessageData();
    data.setMessageBody(new String(messageExt.getBody()));
    data.setMessageKey(messageExt.getKeys());
    data.setMessageTag(messageExt.getTags());
    data.setMessageTopic(messageExt.getTopic());
    data.setMessageType(MqMessageTypeEnum.CONSUMER_MESSAGE.messageType());
    return data;
}
Also used : MqMessageData(com.paascloud.provider.model.domain.MqMessageData)

Example 4 with MqMessageData

use of com.paascloud.provider.model.domain.MqMessageData in project paascloud-master by paascloud.

the class MdcProductServiceImpl method deleteProductById.

@Override
public void deleteProductById(final Long id) {
    MdcProduct product = mdcProductMapper.selectByPrimaryKey(id);
    if (product != null) {
        String body = product.getProductCode();
        String topic = AliyunMqTopicConstants.MqTagEnum.DELETE_ATTACHMENT.getTopic();
        String tag = AliyunMqTopicConstants.MqTagEnum.DELETE_ATTACHMENT.getTag();
        String key = RedisKeyUtil.createMqKey(topic, tag, product.getProductCode(), body);
        MqMessageData mqMessageData = new MqMessageData(body, topic, tag, key);
        mdcProductManager.deleteProduct(mqMessageData, id);
    }
}
Also used : MqMessageData(com.paascloud.provider.model.domain.MqMessageData) MdcProduct(com.paascloud.provider.model.domain.MdcProduct)

Example 5 with MqMessageData

use of com.paascloud.provider.model.domain.MqMessageData 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)

Aggregations

MqMessageData (com.paascloud.provider.model.domain.MqMessageData)10 UacBizException (com.paascloud.provider.model.exceptions.UacBizException)4 TpcBizException (com.paascloud.provider.exceptions.TpcBizException)2 MdcProduct (com.paascloud.provider.model.domain.MdcProduct)2 Date (java.util.Date)2 Around (org.aspectj.lang.annotation.Around)2 AliyunSmsConstants (com.paascloud.base.constant.AliyunSmsConstants)1 MqConsumerStore (com.paascloud.provider.annotation.MqConsumerStore)1 MqProducerStore (com.paascloud.provider.annotation.MqProducerStore)1 UacUser (com.paascloud.provider.model.domain.UacUser)1 PcSendEmailRequest (com.paascloud.provider.model.dto.PcSendEmailRequest)1 PcSendSmsRequest (com.paascloud.provider.model.dto.PcSendSmsRequest)1 UpdateAttachmentDto (com.paascloud.provider.model.dto.UpdateAttachmentDto)1 DelayLevelEnum (com.paascloud.provider.model.enums.DelayLevelEnum)1 MqSendTypeEnum (com.paascloud.provider.model.enums.MqSendTypeEnum)1 List (java.util.List)1 MessageExt (org.apache.rocketmq.common.message.MessageExt)1 JoinPoint (org.aspectj.lang.JoinPoint)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Example (tk.mybatis.mapper.entity.Example)1