Java Code Examples for org.apache.rocketmq.common.message.MessageExt#getTopic()

The following examples show how to use org.apache.rocketmq.common.message.MessageExt#getTopic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionalMessageBridge.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public boolean putOpMessage(MessageExt messageExt, String opType) {
        MessageQueue messageQueue = new MessageQueue(messageExt.getTopic(),
            this.brokerController.getBrokerConfig().getBrokerName(), messageExt.getQueueId());
        if (TransactionalMessageUtil.REMOVETAG.equals(opType)) {
//            事务消息提交或回滚时添加删除标记=》
            return addRemoveTagInTransactionOp(messageExt, messageQueue);
        }
        return true;
    }
 
Example 2
Source File: TransactionalMessageBridge.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 添加处理结果的Message
 * @param messageExt prepareMessage
 * @param opType 删除类型
 * @return ;
 */
public boolean putOpMessage(MessageExt messageExt, String opType) {

    MessageQueue messageQueue = new MessageQueue(messageExt.getTopic(),
        this.brokerController.getBrokerConfig().getBrokerName(), messageExt.getQueueId());

    if (TransactionalMessageUtil.REMOVETAG.equals(opType)) {
        return addRemoveTagInTransactionOp(messageExt, messageQueue);
    }
    return true;
}
 
Example 3
Source File: UacPushMessageListener.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: TransactionalMessageBridge.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public boolean putOpMessage(MessageExt messageExt, String opType) {
    MessageQueue messageQueue = new MessageQueue(messageExt.getTopic(),
        this.brokerController.getBrokerConfig().getBrokerName(), messageExt.getQueueId());
    if (TransactionalMessageUtil.REMOVETAG.equals(opType)) {
        return addRemoveTagInTransactionOp(messageExt, messageQueue);
    }
    return true;
}
 
Example 5
Source File: OptPushMessageListener.java    From paascloud-master with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}