首页 > 代码库 > Hadoop实战-Flume之自定义Source(十八)
Hadoop实战-Flume之自定义Source(十八)
import java.nio.charset.Charset; import java.util.HashMap; import java.util.Random; import org.apache.flume.Context; 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; public class MySouce extends AbstractSource implements Configurable, PollableSource { @Override public long getBackOffSleepIncrement() { // TODO Auto-generated method stub return 0; } @Override public long getMaxBackOffSleepInterval() { // TODO Auto-generated method stub return 0; } @Override public Status process() throws EventDeliveryException { try { while (true) { int max = 20; int min = 10; Random random = new Random(); int s = random.nextInt(max) % (max - min + 1) + min; HashMap<String, String> header = new HashMap<String, String>(); header.put("id", Integer.toString(s)); this.getChannelProcessor().processEvent( EventBuilder.withBody(Integer.toString(s), Charset.forName("UTF-8"), header)); Thread.sleep(1000); } } catch (InterruptedException e) { e.printStackTrace(); } return null; } @Override public void configure(Context arg0) { // TODO Auto-generated method stub } }
Hadoop实战-Flume之自定义Source(十八)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。