com.aliyun.openservices.ons.api.impl.rocketmq.ONSUtil Maven / Gradle / Ivy
package com.aliyun.openservices.ons.api.impl.rocketmq;
import com.aliyun.openservices.ons.api.Constants;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.MessageConst;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.MessageExt;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageAccessor;
import com.aliyun.openservices.ons.api.exception.ONSClientException;
public class ONSUtil {
private static final Set RESERVED_KEY_SET_RMQ = new HashSet();
private static final Set RESERVED_KEY_SET_ONS = new HashSet();
static {
/**
* RMQ
*/
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_KEYS);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_TAGS);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_WAIT_STORE_MSG_OK);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_DELAY_TIME_LEVEL);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_RETRY_TOPIC);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_REAL_TOPIC);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_REAL_QUEUE_ID);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_TRANSACTION_PREPARED);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_PRODUCER_GROUP);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_MIN_OFFSET);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_MAX_OFFSET);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_TRANSIENT_MSHA_RETRY);
RESERVED_KEY_SET_RMQ.add(MessageConst.PROPERTY_MSHA_TRANSFORM);
/**
* ONS
*/
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.TAG);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.KEY);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.MSGID);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.RECONSUMETIMES);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.STARTDELIVERTIME);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.BORNHOST);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.BORNTIMESTAMP);
RESERVED_KEY_SET_ONS.add(Message.SystemPropKey.SHARDINGKEY);
}
public static com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.Message msgConvert(
com.aliyun.openservices.ons.api.Message message) {
com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.Message msgRMQ = new com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.Message();
if (message == null) {
throw new ONSClientException("\'message\' is null");
}
if (message.getTopic() != null) {
msgRMQ.setTopic(message.getTopic());
}
if (message.getKey() != null) {
msgRMQ.setKeys(message.getKey());
}
if (message.getTag() != null) {
msgRMQ.setTags(message.getTag());
}
if (message.getStartDeliverTime() > 0) {
msgRMQ.putUserProperty(Message.SystemPropKey.STARTDELIVERTIME, String.valueOf(message.getStartDeliverTime()));
}
if (message.getBody() != null) {
msgRMQ.setBody(message.getBody());
}
if (message.getShardingKey() != null && !message.getShardingKey().isEmpty()) {
msgRMQ.putUserProperty(Message.SystemPropKey.SHARDINGKEY, message.getShardingKey());
}
Properties systemProperties = MessageAccessor.getSystemProperties(message);
if (systemProperties != null) {
Iterator> it = systemProperties.entrySet().iterator();
while (it.hasNext()) {
Entry