Java Code Examples for org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus#valueOf()

The following examples show how to use org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus#valueOf() . 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: 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 2
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 3
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));
}