storm-kafka 整合框架

storm ,kafka 版本都为1.2.2

所需的配置文件

public class KafkaSpoutAllConfig {

    public static Properties kafkaStormConsumer()
    {
        Properties props = new Properties();
        props.put("bootstrap.servers", "SH04_TEST:5121,SH05_TEST:5121,SH06_TEST:5121");
        props.put("group.id", "saturn-mid-br");
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms", "1000");
        props.put("session.timeout.ms", "30000");
        props.put("auto.offset.reset", "latest");
        props.put("key.deserializer", "StringDeserializer.class.getName()");
        props.put("value.deserializer", "StringDeserializer.class.getName()");
        return props;
    }
    public static Properties kafkaStormProducer()
    {
        Properties props = new Properties();
        props.put("bootstrap.servers", "SH04_TEST:5121,SH05_TEST:5121,SH06_TEST:5121");
        props.put("acks", "all");
        props.put("retries", "0");
        props.put("batch.size", "4096");
        props.put("linger.ms", "1");
        props.put("buffer.memory", "40960");
        props.put("key.serializer", StringSerializer.class.getName());
        props.put("value.serializer", StringSerializer.class.getName());
        return props;
    }

    public static KafkaSpoutConfig<String,String> newKafkaSpoutConfig(List<String> topics)
    {
        return  KafkaSpoutConfig.builder("SH04_TEST:5121,SH05_TEST:5121,SH06_TEST:5121",topics)
                .setProp(ConsumerConfig.GROUP_ID_CONFIG, "saturn-mid-br")
                .setProp(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, 200)
                .setRetry(getRetryService())  // 定义重试策略
                .setOffsetCommitPeriodMs(10000)  // 定时提交偏移量的时间间隔,默认是15s
                .setFirstPollOffsetStrategy(org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.LATEST)
                .setMaxUncommittedOffsets(250)
                .build();
    }

    private static KafkaSpoutRetryService getRetryService() {
        return new KafkaSpoutRetryExponentialBackoff(KafkaSpoutRetryExponentialBackoff.TimeInterval.microSeconds(500),
                KafkaSpoutRetryExponentialBackoff.TimeInterval.milliSeconds(2), Integer.MAX_VALUE, KafkaSpoutRetryExponentialBackoff.TimeInterval.seconds(10));
    }
}

Topology文件:

kafka-spout框架提供一个自身的spout ,建立Spout直接new KafkaSpout。

builder.setSpout("KafkaSpout",new KafkaSpout<String, String>(KafkaSpoutAllConfig.newKafkaSpoutConfig(topicList)) , 1);
        builder.setBolt("DispatcherBolt",new DisPatcherBolt(),2).shuffleGrouping("KafkaSpout");
        //sport MatchInfo
        builder.setBolt("SportProcessBolt",new SportProcessBolt(),2).shuffleGrouping("DispatcherBolt","SportItem");
        builder.setBolt("MatchInfoProcessBolt",new MatchInfoProcessBolt(),2).shuffleGrouping("SportProcessBolt","MatchInfoItem");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值