<?xml version="1.0"?> <!-- 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. --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
String topic = ""; //队列名 String zkRoot = "/kafkastorm"; //kafka在zookeeper中记录offset的根目录,无需改变 String id = ""; // consumer id String kafkaZk = ""; //kafka的zookeeper地址 BrokerHosts brokerHosts = new ZkHosts(kafkaZk); SpoutConfig kafkaConfig = new SpoutConfig(brokerHosts, topic, zkRoot, id); kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); kafkaConfig.ignoreZkOffsets = true; //false时使用kafka中存储的offset信息 kafkaConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime(); //读取数据开始位置,只有ignoreZkOffsets设为true时startOffsetTime才能生效 kafkaConfig.zkServers = new ArrayList<String>(){ { add("1"); //存储kafkaoffset的zookeeper节点 } }; kafkaConfig.zkPort = 2181; TopologyBuilder builder = new TopologyBuilder(); builder.setSpout(topic, new KafkaSpout(kafkaConfig), 10); //并行度不能高于kafka分区数 builder.setBolt....
storm-hdfs
HdfsBolt支持向hdfs写入数据
使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14
SyncPolicy syncPolicy = new CountSyncPolicy(100); //每100条hdfs同步一次磁盘 DailyRotationPolicy rotationPolicy = new DailyRotationPolicy(); //文件每天归档
FileFolderByDateNameFormat fileNameFormat = new FileFolderByDateNameFormat() .withPath("/user/lcy/jdata"); //hdfs路径 RecordFormat format = new DelimitedRecordFormat() .withFieldDelimiter(","); //不同field之间的分隔符