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

The following examples show how to use org.apache.rocketmq.common.message.MessageExt#getTags() . 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: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private Message queryMessageByOffset(String nameServer, String topic, String brokerName, Integer qid, long offset) throws Exception {
    DefaultMQPullConsumer mqPullConsumer = getMqPullConsumer(nameServer);

    MessageQueue mq = new MessageQueue();
    mq.setTopic(topic);
    mq.setBrokerName(brokerName);
    mq.setQueueId(qid);

    PullResult pullResult = mqPullConsumer.pull(mq, "*", offset, 1, 5000);
    if (pullResult == null || pullResult.getPullStatus() != PullStatus.FOUND) {
        throw new MqException(String.format("[RMQ] message not exsit, nsrv:%s, topic:%s, brokerName:%s, qid:%s, offset:%d", nameServer, topic, brokerName, qid, offset));
    }

    MessageExt messageExt = pullResult.getMsgFoundList().get(0);
    if (messageExt.getBody().length == 0) {
        return null;
    }

    String msg;
    if (CodecsUtils.isUtf8(messageExt.getBody())) {
        msg = new String(messageExt.getBody(), "UTF-8");
    } else {
        msg = java.util.Base64.getEncoder().encodeToString(messageExt.getBody());
    }
    return new Message(brokerName + "_" + qid, offset, msg, messageExt.getTags(), messageExt.getKeys(), messageExt.getStoreSize(), messageExt.getBornTimestamp());
}
 
Example 2
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private Message queryMessageByOffset(String nameServer, String topic, String brokerName, Integer qid, long offset) throws Exception {
    DefaultMQPullConsumer mqPullConsumer = getMqPullConsumer(nameServer);

    MessageQueue mq = new MessageQueue();
    mq.setTopic(topic);
    mq.setBrokerName(brokerName);
    mq.setQueueId(qid);

    PullResult pullResult = mqPullConsumer.pull(mq, "*", offset, 1, 5000);
    if (pullResult == null || pullResult.getPullStatus() != PullStatus.FOUND) {
        throw new MqException(String.format("[RMQ] message not exsit, nsrv:%s, topic:%s, brokerName:%s, qid:%s, offset:%d", nameServer, topic, brokerName, qid, offset));
    }

    MessageExt messageExt = pullResult.getMsgFoundList().get(0);
    if (messageExt.getBody().length == 0) {
        return null;
    }

    String msg;
    if (CodecsUtils.isUtf8(messageExt.getBody())) {
        msg = new String(messageExt.getBody(), "UTF-8");
    } else {
        msg = java.util.Base64.getEncoder().encodeToString(messageExt.getBody());
    }
    return new Message(brokerName + "_" + qid, offset, msg, messageExt.getTags(), messageExt.getKeys(), messageExt.getStoreSize(), messageExt.getBornTimestamp());
}
 
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: 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;
}