경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
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 86367
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78816
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95575
18 TensorFlow Lite 101 - MoblieNet 맛보기 file 졸리운_곰 2018.05.30 1089
17 Apache MXNet에서 사전 트레이닝된 모델을 사용해 보세요. 졸리운_곰 2018.05.30 988
16 MXNet을 활용한 이미지 분류 앱 개발하기 file 졸리운_곰 2018.05.30 1424
15 세상에 있는 (거의) 모든 머신러닝 문제 공략법 file 졸리운_곰 2018.05.30 1119
14 sklearn 내부의 pickle lib 를 통해 모델을 저장하고 다시 로드하여 재사용할 수 있다. 졸리운_곰 2018.05.30 1638
13 텐서플로우 기반 딥러닝 훈련 모델 파일 저장, 로딩 및 재활용 file 졸리운_곰 2018.05.30 1767
12 TensorFlow 모델을 저장하고 불러오기 (save and restore) 졸리운_곰 2018.05.30 1638
11 텐서플로우(TensorFlow)를 이용해서 글자 생성(Text Generation) 해보기 – Recurrent Neural Networks(RNNs) 예제 – Char-RNN file 졸리운_곰 2018.05.13 1122
10 외장형 그래픽카드로 우분투에서 텐서플로우 사용 How to setup an eGPU on Ubuntu for TensorFlow file 졸리운_곰 2018.05.09 1426
9 Keras and NLTK 케라스를 이용한 NLTK 자연어처리 졸리운_곰 2018.05.08 1603
8 Windows7에서 "처음 심층 학습 프로그램」을 사경 보면 (1-2) 제 1 장 후반 file 졸리운_곰 2018.05.08 1139
7 CSLAIER CSLAIER에 의한 LSTM file 졸리운_곰 2018.05.08 1663
6 Tensorboard 사용하기 1 file 졸리운_곰 2018.05.08 1416
5 텐서보드 사용법 file 졸리운_곰 2018.05.08 1408
4 Ubuntu 18.04 Settings for TensorFlow 설치 file 졸리운_곰 2018.05.08 1183
3 딥러닝용 서버 설치기 file 졸리운_곰 2018.05.07 1392
2 Installing Tensorflow GPU on Ubuntu 18.04 LTS file 졸리운_곰 2018.05.06 1215
1 TensorFlow Lite 101 - MoblieNet 맛보기 file 졸리운_곰 2018.04.07 1273
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED