Search in sources :

Example 11 with BytesMessage

use of io.openmessaging.BytesMessage 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 12 with BytesMessage

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

the class AbstractOMSProducer method createBytesMessageToQueue.

@Override
public BytesMessage createBytesMessageToQueue(final String queue, final byte[] body) {
    BytesMessage bytesMessage = new BytesMessageImpl();
    bytesMessage.setBody(body);
    bytesMessage.headers().put(MessageHeader.QUEUE, queue);
    return bytesMessage;
}
Also used : BytesMessageImpl(io.openmessaging.rocketmq.domain.BytesMessageImpl) BytesMessage(io.openmessaging.BytesMessage)

Example 13 with BytesMessage

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

the class AbstractOMSProducer method createBytesMessageToTopic.

@Override
public BytesMessage createBytesMessageToTopic(final String topic, final byte[] body) {
    BytesMessage bytesMessage = new BytesMessageImpl();
    bytesMessage.setBody(body);
    bytesMessage.headers().put(MessageHeader.TOPIC, topic);
    return bytesMessage;
}
Also used : BytesMessageImpl(io.openmessaging.rocketmq.domain.BytesMessageImpl) BytesMessage(io.openmessaging.BytesMessage)

Example 14 with BytesMessage

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

the class SequenceProducerImpl method commit.

@Override
public synchronized void commit() {
    List<Message> messages = new ArrayList<>();
    msgCacheQueue.drainTo(messages);
    List<org.apache.rocketmq.common.message.Message> rmqMessages = new ArrayList<>();
    for (Message message : messages) {
        rmqMessages.add(OMSUtil.msgConvert((BytesMessage) message));
    }
    if (rmqMessages.size() == 0) {
        return;
    }
    try {
        SendResult sendResult = this.rocketmqProducer.send(rmqMessages);
        String[] msgIdArray = sendResult.getMsgId().split(",");
        for (int i = 0; i < messages.size(); i++) {
            Message message = messages.get(i);
            message.headers().put(MessageHeader.MESSAGE_ID, msgIdArray[i]);
        }
    } catch (Exception e) {
        throw checkProducerException("", "", e);
    }
}
Also used : Message(io.openmessaging.Message) BytesMessage(io.openmessaging.BytesMessage) SendResult(org.apache.rocketmq.client.producer.SendResult) ArrayList(java.util.ArrayList) BytesMessage(io.openmessaging.BytesMessage) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 15 with BytesMessage

use of io.openmessaging.BytesMessage 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)

Aggregations

BytesMessage (io.openmessaging.BytesMessage)18 Test (org.junit.Test)8 Message (io.openmessaging.Message)6 BytesMessageImpl (io.openmessaging.rocketmq.domain.BytesMessageImpl)6 KeyValue (io.openmessaging.KeyValue)4 SendResult (org.apache.rocketmq.client.producer.SendResult)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MessageListener (io.openmessaging.MessageListener)2 ReceivedMessageContext (io.openmessaging.ReceivedMessageContext)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MessageListenerConcurrently (org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2