use of com.paascloud.provider.annotation.MqConsumerStore 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.annotation.MqConsumerStore in project paascloud-master by paascloud.
the class UacPushMessageListener method consumeMessage.
/**
* Consume message consume concurrently status.
*
* @param messageExtList the message ext list
* @param consumeConcurrentlyContext the consume concurrently context
*
* @return the consume concurrently status
*/
@Override
@MqConsumerStore
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> messageExtList, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
MessageExt msg = messageExtList.get(0);
String body = new String(msg.getBody());
String topicName = msg.getTopic();
String tags = msg.getTags();
String keys = msg.getKeys();
try {
MqMessage.checkMessage(body, topicName, tags, keys);
String mqKV = redisService.getKey(keys);
if (PublicUtil.isNotEmpty(mqKV)) {
log.error("MQ消费Topic={},tag={},key={}, 重复消费", topicName, tags, keys);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
if (AliyunMqTopicConstants.MqTopicEnum.TPC_TOPIC.getTopic().equals(topicName)) {
mqMessageService.deleteMessageTopic(body, tags);
} else {
log.info("OPC订单信息消 topicName={} 不存在", topicName);
}
} catch (IllegalArgumentException ex) {
log.error("校验MQ message 失败 ex={}", ex.getMessage(), ex);
} catch (Exception e) {
log.error("处理MQ message 失败 topicName={}, keys={}, ex={}", topicName, keys, e.getMessage(), e);
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
redisService.setKey(keys, keys, 10, TimeUnit.DAYS);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
use of com.paascloud.provider.annotation.MqConsumerStore in project paascloud-master by paascloud.
the class OptPushMessageListener method consumeMessage.
/**
* Consume message consume concurrently status.
*
* @param messageExtList the message ext list
* @param consumeConcurrentlyContext the consume concurrently context
*
* @return the consume concurrently status
*/
@Override
@MqConsumerStore
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> messageExtList, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
MessageExt msg = messageExtList.get(0);
String body = new String(msg.getBody());
String topicName = msg.getTopic();
String tags = msg.getTags();
String keys = msg.getKeys();
log.info("MQ消费Topic={},tag={},key={}", topicName, tags, keys);
ValueOperations<String, String> ops = srt.opsForValue();
// 控制幂等性使用的key
try {
MqMessage.checkMessage(body, topicName, tags, keys);
String mqKV = null;
if (srt.hasKey(keys)) {
mqKV = ops.get(keys);
}
if (PublicUtil.isNotEmpty(mqKV)) {
log.error("MQ消费Topic={},tag={},key={}, 重复消费", topicName, tags, keys);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
if (AliyunMqTopicConstants.MqTopicEnum.SEND_SMS_TOPIC.getTopic().equals(topicName)) {
optSendSmsTopicService.handlerSendSmsTopic(body, topicName, tags, keys);
}
if (AliyunMqTopicConstants.MqTopicEnum.SEND_EMAIL_TOPIC.getTopic().equals(topicName)) {
optSendEmailTopicService.handlerSendEmailTopic(body, topicName, tags, keys);
}
if (AliyunMqTopicConstants.MqTopicEnum.TPC_TOPIC.getTopic().equals(topicName)) {
mqMessageService.deleteMessageTopic(body, tags);
}
if (AliyunMqTopicConstants.MqTopicEnum.MDC_TOPIC.getTopic().equals(topicName)) {
mdcTopicConsumer.handlerSendSmsTopic(body, topicName, tags, keys);
} else {
log.info("OPC订单信息消 topicName={} 不存在", topicName);
}
} catch (IllegalArgumentException ex) {
log.error("校验MQ message 失败 ex={}", ex.getMessage(), ex);
} catch (Exception e) {
log.error("处理MQ message 失败 topicName={}, keys={}, ex={}", topicName, keys, e.getMessage(), e);
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
ops.set(keys, keys, 10, TimeUnit.DAYS);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
Aggregations