com.aliyun.openservices.ons.api.impl.rocketmq.ONSUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gw-boot-starter-aliyun-ons Show documentation
Show all versions of gw-boot-starter-aliyun-ons Show documentation
A Java Utils Libraray By Geewit
package com.aliyun.openservices.ons.api.impl.rocketmq;
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;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
public class ONSUtil {
private static final Set ReservedKeySetRMQ = new HashSet<>();
private static final Set ReservedKeySetONS = new HashSet<>();
static {
/**
* RMQ
*/
ReservedKeySetRMQ.add(MessageConst.PROPERTY_KEYS);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_TAGS);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_WAIT_STORE_MSG_OK);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_DELAY_TIME_LEVEL);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_RETRY_TOPIC);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_REAL_TOPIC);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_REAL_QUEUE_ID);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_TRANSACTION_PREPARED);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_PRODUCER_GROUP);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_MIN_OFFSET);
ReservedKeySetRMQ.add(MessageConst.PROPERTY_MAX_OFFSET);
/**
* ONS
*/
ReservedKeySetONS.add(Message.SystemPropKey.TAG);
ReservedKeySetONS.add(Message.SystemPropKey.KEY);
ReservedKeySetONS.add(Message.SystemPropKey.MSGID);
ReservedKeySetONS.add(Message.SystemPropKey.RECONSUMETIMES);
ReservedKeySetONS.add(Message.SystemPropKey.STARTDELIVERTIME);
ReservedKeySetONS.add(Message.SystemPropKey.BORNHOST);
ReservedKeySetONS.add(Message.SystemPropKey.BORNTIMESTAMP);
ReservedKeySetONS.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) {
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy