Java Code Examples for io.openmessaging.rocketmq.utils.OMSUtil#msgConvert()

The following examples show how to use io.openmessaging.rocketmq.utils.OMSUtil#msgConvert() . 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: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example 2
Source File: SequenceProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example 3
Source File: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example 4
Source File: PushConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> rmqMsgList,
    ConsumeConcurrentlyContext contextRMQ) {
    MessageExt rmqMsg = rmqMsgList.get(0);
    BytesMessage omsMsg = OMSUtil.msgConvert(rmqMsg);

    MessageListener listener = PushConsumerImpl.this.subscribeTable.get(rmqMsg.getTopic());

    if (listener == null) {
        throw new OMSRuntimeException("-1",
            String.format("The topic/queue %s isn't attached to this consumer", rmqMsg.getTopic()));
    }

    final KeyValue contextProperties = OMS.newKeyValue();
    final CountDownLatch sync = new CountDownLatch(1);

    contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, ConsumeConcurrentlyStatus.RECONSUME_LATER.name());

    MessageListener.Context context = new MessageListener.Context() {
        @Override
        public KeyValue attributes() {
            return contextProperties;
        }

        @Override
        public void ack() {
            sync.countDown();
            contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS,
                ConsumeConcurrentlyStatus.CONSUME_SUCCESS.name());
        }
    };
    long begin = System.currentTimeMillis();
    listener.onReceived(omsMsg, context);
    long costs = System.currentTimeMillis() - begin;
    long timeoutMills = clientConfig.getRmqMessageConsumeTimeout() * 60 * 1000;
    try {
        sync.await(Math.max(0, timeoutMills - costs), TimeUnit.MILLISECONDS);
    } catch (InterruptedException ignore) {
    }

    return ConsumeConcurrentlyStatus.valueOf(contextProperties.getString(NonStandardKeys.MESSAGE_CONSUME_STATUS));
}
 
Example 5
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 6
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 7
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 8
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 9
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 10
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 11
Source File: PushConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> rmqMsgList,
    ConsumeConcurrentlyContext contextRMQ) {
    MessageExt rmqMsg = rmqMsgList.get(0);
    BytesMessage omsMsg = OMSUtil.msgConvert(rmqMsg);

    MessageListener listener = PushConsumerImpl.this.subscribeTable.get(rmqMsg.getTopic());

    if (listener == null) {
        throw new OMSRuntimeException("-1",
            String.format("The topic/queue %s isn't attached to this consumer", rmqMsg.getTopic()));
    }

    final KeyValue contextProperties = OMS.newKeyValue();
    final CountDownLatch sync = new CountDownLatch(1);

    contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, ConsumeConcurrentlyStatus.RECONSUME_LATER.name());

    MessageListener.Context context = new MessageListener.Context() {
        @Override
        public KeyValue attributes() {
            return contextProperties;
        }

        @Override
        public void ack() {
            sync.countDown();
            contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS,
                ConsumeConcurrentlyStatus.CONSUME_SUCCESS.name());
        }
    };
    long begin = System.currentTimeMillis();
    listener.onReceived(omsMsg, context);
    long costs = System.currentTimeMillis() - begin;
    long timeoutMills = clientConfig.getRmqMessageConsumeTimeout() * 60 * 1000;
    try {
        sync.await(Math.max(0, timeoutMills - costs), TimeUnit.MILLISECONDS);
    } catch (InterruptedException ignore) {
    }

    return ConsumeConcurrentlyStatus.valueOf(contextProperties.getString(NonStandardKeys.MESSAGE_CONSUME_STATUS));
}
 
Example 12
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 13
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 14
Source File: PushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> rmqMsgList,
            ConsumeConcurrentlyContext contextRMQ) {
            MessageExt rmqMsg = rmqMsgList.get(0);
            BytesMessage omsMsg = OMSUtil.msgConvert(rmqMsg);

            MessageListener listener = PushConsumerImpl.this.subscribeTable.get(rmqMsg.getTopic());

            if (listener == null) {
                throw new OMSRuntimeException("-1",
                    String.format("The topic/queue %s isn't attached to this consumer", rmqMsg.getTopic()));
            }

            final KeyValue contextProperties = OMS.newKeyValue();
//            让一段代码执行完毕后再往下执行
            final CountDownLatch sync = new CountDownLatch(1);

            contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, ConsumeConcurrentlyStatus.RECONSUME_LATER.name());

            MessageListener.Context context = new MessageListener.Context() {
                @Override
                public KeyValue attributes() {
                    return contextProperties;
                }

                @Override
                public void ack() {
                    sync.countDown();
                    contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS,
                        ConsumeConcurrentlyStatus.CONSUME_SUCCESS.name());
                }
            };
            long begin = System.currentTimeMillis();
            listener.onReceived(omsMsg, context);
            long costs = System.currentTimeMillis() - begin;
            long timeoutMills = clientConfig.getRmqMessageConsumeTimeout() * 60 * 1000;
            try {
                sync.await(Math.max(0, timeoutMills - costs), TimeUnit.MILLISECONDS);
            } catch (InterruptedException ignore) {
            }

            return ConsumeConcurrentlyStatus.valueOf(contextProperties.getString(NonStandardKeys.MESSAGE_CONSUME_STATUS));
        }
 
Example 15
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 16
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public Message receive() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 17
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example 18
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}