Search in sources :

Example 36 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OMSUtil method msgConvert.

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
    org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
    rmqMessage.setBody(omsMessage.getBody());
    KeyValue headers = omsMessage.headers();
    KeyValue properties = omsMessage.properties();
    // All destinations in RocketMQ use Topic
    if (headers.containsKey(MessageHeader.TOPIC)) {
        rmqMessage.setTopic(headers.getString(MessageHeader.TOPIC));
        rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    } else {
        rmqMessage.setTopic(headers.getString(MessageHeader.QUEUE));
        rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "QUEUE");
    }
    for (String key : properties.keySet()) {
        MessageAccessor.putProperty(rmqMessage, key, properties.getString(key));
    }
    // Headers has a high priority
    for (String key : headers.keySet()) {
        MessageAccessor.putProperty(rmqMessage, key, headers.getString(key));
    }
    return rmqMessage;
}
Also used : KeyValue(io.openmessaging.KeyValue) BytesMessage(io.openmessaging.BytesMessage)

Example 37 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OMSUtil method msgConvert.

public static BytesMessage msgConvert(org.apache.rocketmq.common.message.MessageExt rmqMsg) {
    BytesMessage omsMsg = new BytesMessageImpl();
    omsMsg.setBody(rmqMsg.getBody());
    KeyValue headers = omsMsg.headers();
    KeyValue properties = omsMsg.properties();
    final Set<Map.Entry<String, String>> entries = rmqMsg.getProperties().entrySet();
    for (final Map.Entry<String, String> entry : entries) {
        if (isOMSHeader(entry.getKey())) {
            headers.put(entry.getKey(), entry.getValue());
        } else {
            properties.put(entry.getKey(), entry.getValue());
        }
    }
    omsMsg.putHeaders(MessageHeader.MESSAGE_ID, rmqMsg.getMsgId());
    if (!rmqMsg.getProperties().containsKey(NonStandardKeys.MESSAGE_DESTINATION) || rmqMsg.getProperties().get(NonStandardKeys.MESSAGE_DESTINATION).equals("TOPIC")) {
        omsMsg.putHeaders(MessageHeader.TOPIC, rmqMsg.getTopic());
    } else {
        omsMsg.putHeaders(MessageHeader.QUEUE, rmqMsg.getTopic());
    }
    omsMsg.putHeaders(MessageHeader.SEARCH_KEY, rmqMsg.getKeys());
    omsMsg.putHeaders(MessageHeader.BORN_HOST, String.valueOf(rmqMsg.getBornHost()));
    omsMsg.putHeaders(MessageHeader.BORN_TIMESTAMP, rmqMsg.getBornTimestamp());
    omsMsg.putHeaders(MessageHeader.STORE_HOST, String.valueOf(rmqMsg.getStoreHost()));
    omsMsg.putHeaders(MessageHeader.STORE_TIMESTAMP, rmqMsg.getStoreTimestamp());
    return omsMsg;
}
Also used : KeyValue(io.openmessaging.KeyValue) BytesMessageImpl(io.openmessaging.rocketmq.domain.BytesMessageImpl) BytesMessage(io.openmessaging.BytesMessage) Map(java.util.Map)

Example 38 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq by apache.

the class OMSUtil method msgConvert.

public static BytesMessage msgConvert(org.apache.rocketmq.common.message.MessageExt rmqMsg) {
    BytesMessage omsMsg = new BytesMessageImpl();
    omsMsg.setBody(rmqMsg.getBody());
    KeyValue headers = omsMsg.headers();
    KeyValue properties = omsMsg.properties();
    final Set<Map.Entry<String, String>> entries = rmqMsg.getProperties().entrySet();
    for (final Map.Entry<String, String> entry : entries) {
        if (isOMSHeader(entry.getKey())) {
            headers.put(entry.getKey(), entry.getValue());
        } else {
            properties.put(entry.getKey(), entry.getValue());
        }
    }
    omsMsg.putHeaders(MessageHeader.MESSAGE_ID, rmqMsg.getMsgId());
    if (!rmqMsg.getProperties().containsKey(NonStandardKeys.MESSAGE_DESTINATION) || rmqMsg.getProperties().get(NonStandardKeys.MESSAGE_DESTINATION).equals("TOPIC")) {
        omsMsg.putHeaders(MessageHeader.TOPIC, rmqMsg.getTopic());
    } else {
        omsMsg.putHeaders(MessageHeader.QUEUE, rmqMsg.getTopic());
    }
    omsMsg.putHeaders(MessageHeader.SEARCH_KEY, rmqMsg.getKeys());
    omsMsg.putHeaders(MessageHeader.BORN_HOST, String.valueOf(rmqMsg.getBornHost()));
    omsMsg.putHeaders(MessageHeader.BORN_TIMESTAMP, rmqMsg.getBornTimestamp());
    omsMsg.putHeaders(MessageHeader.STORE_HOST, String.valueOf(rmqMsg.getStoreHost()));
    omsMsg.putHeaders(MessageHeader.STORE_TIMESTAMP, rmqMsg.getStoreTimestamp());
    return omsMsg;
}
Also used : KeyValue(io.openmessaging.KeyValue) BytesMessageImpl(io.openmessaging.rocketmq.domain.BytesMessageImpl) BytesMessage(io.openmessaging.BytesMessage) Map(java.util.Map)

Example 39 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq by apache.

the class OMSUtil method msgConvert.

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
    org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
    rmqMessage.setBody(omsMessage.getBody());
    KeyValue headers = omsMessage.headers();
    KeyValue properties = omsMessage.properties();
    // All destinations in RocketMQ use Topic
    if (headers.containsKey(MessageHeader.TOPIC)) {
        rmqMessage.setTopic(headers.getString(MessageHeader.TOPIC));
        rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
    } else {
        rmqMessage.setTopic(headers.getString(MessageHeader.QUEUE));
        rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "QUEUE");
    }
    for (String key : properties.keySet()) {
        MessageAccessor.putProperty(rmqMessage, key, properties.getString(key));
    }
    // Headers has a high priority
    for (String key : headers.keySet()) {
        MessageAccessor.putProperty(rmqMessage, key, headers.getString(key));
    }
    return rmqMessage;
}
Also used : KeyValue(io.openmessaging.KeyValue) BytesMessage(io.openmessaging.BytesMessage)

Aggregations

KeyValue (io.openmessaging.KeyValue)39 DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)29 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 Map (java.util.Map)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)5 BytesMessage (io.openmessaging.BytesMessage)4 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)4 PositionStorageReader (io.openmessaging.connector.api.PositionStorageReader)3 SourceTaskContext (io.openmessaging.connector.api.source.SourceTaskContext)3 ByteBuffer (java.nio.ByteBuffer)3 QueueMetaData (io.openmessaging.connector.api.common.QueueMetaData)2 SinkTaskContext (io.openmessaging.connector.api.sink.SinkTaskContext)2 BytesMessageImpl (io.openmessaging.rocketmq.domain.BytesMessageImpl)2 Set (java.util.Set)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)2