tree: e5592a3e26c9adaa48c8f8104c3ccc9b5085af8b [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.md
external/storm-rocketmq/README.md

Storm RocketMQ

Storm/Trident integration for RocketMQ. This package includes the core spout, bolt and trident states that allows a storm topology to either write storm tuples into a topic or read from topics in a storm topology.

Read from Topic

The spout included in this package for reading data from a topic.

RocketMqSpout

To use the RocketMqSpout, you construct an instance of it by specifying a Properties instance which including rocketmq configs. RocketMqSpout uses RocketMQ MQPushConsumer as the default implementation. PushConsumer is a high level consumer API, wrapping the pulling details. Looks like broker push messages to consumer. RocketMqSpout‘s messages retrying depends on RocketMQ’s push mode retry policy.

       Properties properties = new Properties();
       properties.setProperty(SpoutConfig.NAME_SERVER_ADDR, nameserverAddr);
       properties.setProperty(SpoutConfig.CONSUMER_GROUP, group);
       properties.setProperty(SpoutConfig.CONSUMER_TOPIC, topic);

       RocketMqSpout spout = new RocketMqSpout(properties);

Write into Topic

The bolt and trident state included in this package for write data into a topic.

TupleToMessageMapper

The main API for mapping Storm tuple to a RocketMQ Message is the org.apache.storm.rocketmq.common.mapper.TupleToMessageMapper interface:

public interface TupleToMessageMapper extends Serializable {
    String getKeyFromTuple(ITuple tuple);
    byte[] getValueFromTuple(ITuple tuple);
}

FieldNameBasedTupleToMessageMapper

storm-rocketmq includes a general purpose TupleToMessageMapper implementation called FieldNameBasedTupleToMessageMapper.

TopicSelector

The main API for selecting topic and tags is the org.apache.storm.rocketmq.common.selector.TopicSelector interface:

public interface TopicSelector extends Serializable {
    String getTopic(ITuple tuple);
    String getTag(ITuple tuple);
}

DefaultTopicSelector/FieldNameBasedTopicSelector

storm-rocketmq includes general purpose TopicSelector implementations called DefaultTopicSelector and FieldNameBasedTopicSelector.

RocketMqBolt

To use the RocketMqBolt, you construct an instance of it by specifying TupleToMessageMapper, TopicSelector and Properties instances. RocketMqBolt send messages async by default. You can change this by invoking withAsync(false).

       TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
       TopicSelector selector = new DefaultTopicSelector(topic);

       properties = new Properties();
       properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);

       RocketMqBolt insertBolt = new RocketMqBolt()
               .withMapper(mapper)
               .withSelector(selector)
               .withProperties(properties);

Trident State

We support trident persistent state that can be used with trident topologies. To create a RocketMQ persistent trident state you need to initialize it with the TupleToMessageMapper, TopicSelector, Properties instances. See the example below:

       TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
       TopicSelector selector = new DefaultTopicSelector(topic);

       Properties properties = new Properties();
       properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);

       RocketMqState.Options options = new RocketMqState.Options()
               .withMapper(mapper)
               .withSelector(selector)
               .withProperties(properties);

       StateFactory factory = new RocketMqStateFactory(options);

       TridentTopology topology = new TridentTopology();
       Stream stream = topology.newStream("spout1", spout);

       stream.partitionPersist(factory, fields,
               new RocketMqStateUpdater(), new Fields());

Configurations

Producer Configurations

NAMEDESCRIPTIONDEFAULT
nameserver.addressname server address Requirednull
nameserver.poll.intervalname server poll topic info interval30000
brokerserver.heartbeat.intervalbroker server heartbeat interval30000
producer.groupproducer group$UUID
producer.retry.timesproducer send messages retry times3
producer.timeoutproducer send messages timeout3000

Consumer Configurations

NAMEDESCRIPTIONDEFAULT
nameserver.addressname server address Requirednull
nameserver.poll.intervalname server poll topic info interval30000
brokerserver.heartbeat.intervalbroker server heartbeat interval30000
consumer.groupconsumer group Requirednull
consumer.topicconsumer topic Requirednull
consumer.tagconsumer topic tag*
consumer.offset.reset.towhat to do when there is no initial offset on the serverlatest/earliest/timestamp
consumer.offset.from.timestampthe timestamp when consumer.offset.reset.to=timestamp was set$TIMESTAMP
consumer.messages.orderlyif the consumer topic is orderedfalse
consumer.offset.persist.intervalauto commit offset interval5000
consumer.min.threadsconsumer min threads20
consumer.max.threadsconsumer max threads64
consumer.callback.executor.threadsclient callback executor threads$availableProcessors
consumer.batch.sizeconsumer messages batch size32
consumer.batch.process.timeoutconsumer messages batch process timeout$TOPOLOGY_MESSAGE_TIMEOUT_SECS + 10s

License

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.

Committer Sponsors