Github user vesense commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2024#discussion_r111551137
  
    --- Diff: 
external/storm-rocketmq/src/main/java/org/apache/storm/rocketmq/spout/RocketMQSpout.java
 ---
    @@ -0,0 +1,189 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.storm.rocketmq.spout;
    +
    +import org.apache.commons.lang.Validate;
    +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
    +import org.apache.rocketmq.client.consumer.MQPushConsumer;
    +import 
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
    +import 
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
    +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
    +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
    +import 
org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
    +import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
    +import org.apache.rocketmq.client.exception.MQClientException;
    +import org.apache.rocketmq.common.message.MessageExt;
    +import org.apache.storm.Config;
    +import org.apache.storm.rocketmq.DefaultMessageRetryManager;
    +import org.apache.storm.rocketmq.MessageRetryManager;
    +import org.apache.storm.rocketmq.MessageSet;
    +import org.apache.storm.rocketmq.RocketMQConfig;
    +import org.apache.storm.rocketmq.SpoutConfig;
    +import org.apache.storm.spout.SpoutOutputCollector;
    +import org.apache.storm.task.TopologyContext;
    +import org.apache.storm.topology.IRichSpout;
    +import org.apache.storm.topology.OutputFieldsDeclarer;
    +import org.apache.storm.tuple.Fields;
    +import org.apache.storm.tuple.Values;
    +import org.apache.storm.utils.ObjectReader;
    +
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Properties;
    +import java.util.concurrent.BlockingQueue;
    +import java.util.concurrent.LinkedBlockingQueue;
    +
    +import static org.apache.storm.rocketmq.RocketMQUtils.getBoolean;
    +import static org.apache.storm.rocketmq.RocketMQUtils.getInteger;
    +
    +/**
    + * RocketMQSpout uses MQPushConsumer as the default implementation.
    + * PushConsumer is a high level consumer API, wrapping the pulling details
    + * Looks like broker push messages to consumer
    + */
    +public class RocketMQSpout implements IRichSpout {
    +    // TODO add metrics
    +
    +    private static MQPushConsumer consumer;
    +    private SpoutOutputCollector collector;
    +    private BlockingQueue<MessageSet> queue;
    +
    +    private Properties properties;
    +    private MessageRetryManager messageRetryManager;
    +
    +    public RocketMQSpout(Properties properties) {
    +        this.properties = properties;
    +    }
    +
    +    @Override
    +    public void open(Map conf, TopologyContext context, 
SpoutOutputCollector collector) {
    +        Validate.notEmpty(properties, "Consumer properties can not be 
empty");
    +        boolean ordered = getBoolean(properties, 
RocketMQConfig.CONSUMER_MESSAGES_ORDERLY, false);
    +
    +        int queueSize = getInteger(properties, SpoutConfig.QUEUE_SIZE, 
ObjectReader.getInt(conf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING)));
    +        queue = new LinkedBlockingQueue<>(queueSize);
    +
    +        // Since RocketMQ Consumer is thread-safe, RocketMQSpout uses a 
single
    +        // consumer instance across threads to improve the performance.
    +        synchronized (RocketMQSpout.class) {
    +            if (consumer == null) {
    +                consumer = new DefaultMQPushConsumer();
    +                RocketMQConfig.buildConsumerConfigs(properties, 
(DefaultMQPushConsumer)consumer);
    +
    +                if (ordered) {
    +                    consumer.registerMessageListener(new 
MessageListenerOrderly() {
    --- End diff --
    
    In fact, the RocketMQ "push" mode is still pulling data from broker. 
PushConsumer is a high level consumer API, wrapping the pulling details, looks 
like broker push messages to consumer.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to