경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

[flume] pollable source 플럼 주기적 실행 custom sources in flume

Custom Source in Flume

 
 
Flume provides a way where you can write your own source.As we know that there are default source type available in flume like exec,spoolDir,Tiwtter. Here I have a tried small demonstration for custom flume source.In this example I have written MySource java class which will read single line from input and concatenate them as output and it will pass it to channel.
 
Example:
Sample Input File :
 
20
50
50
04
17
59
18
43
28
58
27
81
 
Sample Output File :
 
20
2050
205050
20505004
2050500417
205050041759
20505004175918
2050500417591843
205050041759184328
20505004175918432858
 
First line is concatenated with other and process continues in this way.
 
Here is my Java Code.
 
MySource.Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.EventDeliveryException;
import org.apache.flume.PollableSource;
import org.apache.flume.conf.Configurable;
import org.apache.flume.event.EventBuilder;
import org.apache.flume.source.AbstractSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class MySource extends AbstractSource implements Configurable, PollableSource {
 
  private static final Logger logger = LoggerFactory.getLogger(MySource.class);
  private String myProp;
  BufferedReader br;
  Thread tailThread;
  @Override
  public void configure(Context context) {
    String myProp = context.getString("filepath", "defaultValue");
    logger.info("Path Property==============>" + myProp);
    this.myProp = myProp;
  }
 
  @Override
  public void start() {
 ConcatRunner t = new ConcatRunner();
 tailThread = new Thread(t);
 tailThread.start();
}
 
  @Override
  public void stop () {
 
  }
 
@Override
public Status process() throws EventDeliveryException {
// TODO Auto-generated method stub
return null;
}
 
private class ConcatRunner implements Runnable {
 
    @Override
    public void run() {
   Event e;
      String sCurrentLine;
   String finalFlumeString = "";
   
   try
     {
      br = new BufferedReader(new FileReader(myProp));
 
       while ((sCurrentLine = br.readLine()) != null) {
     System.out.println(sCurrentLine);
     finalFlumeString = finalFlumeString +  sCurrentLine ; // Concatinating String
     e = EventBuilder.withBody(finalFlumeString,
                 Charset.forName("UTF-8"));
     getChannelProcessor().processEvent(e);
     Thread.sleep(3000);
    }
     }
     catch(Exception ex){
      System.out.println("Exception in Reading File" + ex.getMessage());      
     }
     try {
     if (br != null)br.close();
    } catch (IOException ex) {
     ex.printStackTrace();
    }
 
            }
} //ConcatRunner Over 
}
 
FlumeConfig.conf File :
 
a1.sources = r1
a1.channels = c1
a1.sinks = k1
 
#source
a1.sources.r1.type = MySource
a1.sources.r1.restart = true
a1.sources.r1.filepath = /root/input.txt
#sink
 
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /flume/events/
a1.sinks.k1.hdfs.filePrefix = events-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.fileType = DataStream
#channel
a1.channels.c1.type = memory
 
#connect
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
 
 
Before you proceed for running job , create Jar of your  java project and place it into lib folder of Flume(/usr/lib/flume/lib).
 
Once your are done with above then fire following command form shell.
 
flume-ng agent -n a1  -f FlumeConfig.conf
 
Output of Job:
 
 
 
<This Part is optional>
Apart from above , I have created a shell script which will generate input for you.This script expects two parameter 1. No of Rows 2. Delay Time for generating next row, I have delay time as 2 sec. You can change it as per your need.Here is a sample shell script
 
#!/bin/sh
 
echo "Please enter the size in terms of rows you want to generate the random file data"
read rows
#rows=35090
 
echo "Please enter the delay time needed in between the writing of the rows"
read delayTime
 
#Delete the tmp & generatedRandomDataFile files if they already exist
rm -f tmp
rm -f generatedRandomDataFile
 
start=$(date +%s)
for i in $(seq $rows)
do
tr -dc 0-9 < /dev/urandom | head -c 2 > tmp
gawk '35090=35090' tmp >> generatedRandomDataFile
sleep $delayTime
done
end=$(date +%s)
DIFF=$(( $end - $start ))
echo "File generated is `pwd`/generatedRandomDataFile"
echo "The file generation took $DIFF seconds"
 
Here is sample output of shell script.
 
 
 
 
Reference :
 
https://flume.apache.org/FlumeDeveloperGuide.html 
 
Let me know for any suggestion.
 
Cheers!!!!!!!!!!!!!!!
 
 
 
 
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86287
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78744
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95486
184 Learning Spark Chapter. 2 스파크 설치 및 무작정 시작하기 file 졸리운_곰 2016.06.12 1275
183 Spark를 설치해서 무작정 돌려보자. file 졸리운_곰 2016.06.12 1920
182 빅데이터 분석에 스파크를 이용해야 하는 5가지 이유 file 졸리운_곰 2016.06.12 1371
181 실시간 'BI'를 실행하라, 스톰과 스파크 설명과 그 선택 방법 file 졸리운_곰 2016.06.12 1374
180 [Cloudera 블로그 번역] Spark 활용하기 : 빅데이터 어플리케이션용 고속 인메모리 컴퓨팅 file 졸리운_곰 2016.06.12 1799
179 MongoDB 스키마 디자인의 함정 졸리운_곰 2016.06.06 1272
178 MongoDB 스키마 디자인을 위한 6가지 규칙 요약 졸리운_곰 2016.06.06 1469
177 MongoDB Schema 디자인 하기 졸리운_곰 2016.06.06 1737
176 [kafka] Producer 구현하기 졸리운_곰 2016.06.05 1525
175 [kafka] Consumer Group Example 졸리운_곰 2016.06.05 1839
174 [책보다낫다] kafka 활용문서 Kafka 0.10.0 Documentation file 졸리운_곰 2016.06.05 3035
173 [책보다 낫다] flume 사용자 가이드 졸리운_곰 2016.06.05 1263
172 Java Client for publishing and consuming messages from Apache Kafka 졸리운_곰 2016.06.05 1245
171 kafka create message : 0.8.0 Producer Example 졸리운_곰 2016.06.05 957
170 Create a topic - Apache Kafka 졸리운_곰 2016.06.05 1304
» [flume] pollable source 플럼 주기적 실행 custom sources in flume file 졸리운_곰 2016.06.05 1172
168 Flume 메트릭 커스텀 리포터 구현 file 졸리운_곰 2016.06.05 1269
167 flume-ng를 윈도에서 구동하려면 졸리운_곰 2016.06.05 1269
166 Using Kafka with Flume 졸리운_곰 2016.06.05 1576
165 Flafka: Apache Flume Meets Apache Kafka for Event Processing file 졸리운_곰 2016.06.05 2883
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED