请选择 进入手机版 | 继续访问电脑版
楼主: ReneeBK
1079 0

[Case Study]Event Count using Java [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49392 个
通用积分
51.6904
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

ReneeBK 发表于 2015-11-16 00:22:44 |显示全部楼层 |坛友微信交流群

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. package org.apache.spark.examples.streaming;
  2. import org.apache.spark.SparkConf;
  3. import org.apache.spark.api.java.function.Function;
  4. import org.apache.spark.examples.streaming.StreamingExamples;
  5. import org.apache.spark.streaming.*;
  6. import org.apache.spark.streaming.api.java.*;
  7. import org.apache.spark.streaming.flume.FlumeUtils;
  8. import org.apache.spark.streaming.flume.SparkFlumeEvent;

  9. /**
  10. *  Produces a count of events received from Flume.
  11. *
  12. *  This should be used in conjunction with an AvroSink in Flume. It will start
  13. *  an Avro server on at the request host:port address and listen for requests.
  14. *  Your Flume AvroSink should be pointed to this address.
  15. *
  16. *  Usage: JavaFlumeEventCount <host> <port>
  17. *    <host> is the host the Flume receiver will be started on - a receiver
  18. *           creates a server and listens for flume events.
  19. *    <port> is the port the Flume receiver will listen on.
  20. *
  21. *  To run this example:
  22. *     `$ bin/run-example org.apache.spark.examples.streaming.JavaFlumeEventCount <host> <port>`
  23. */
  24. public final class JavaFlumeEventCount {
  25.   private JavaFlumeEventCount() {
  26.   }

  27.   public static void main(String[] args) {
  28.     if (args.length != 2) {
  29.       System.err.println("Usage: JavaFlumeEventCount <host> <port>");
  30.       System.exit(1);
  31.     }

  32.     StreamingExamples.setStreamingLogLevels();

  33.     String host = args[0];
  34.     int port = Integer.parseInt(args[1]);

  35.     Duration batchInterval = new Duration(2000);
  36.     SparkConf sparkConf = new SparkConf().setAppName("JavaFlumeEventCount");
  37.     JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, batchInterval);
  38.     JavaReceiverInputDStream<SparkFlumeEvent> flumeStream = FlumeUtils.createStream(ssc, host, port);

  39.     flumeStream.count();

  40.     flumeStream.count().map(new Function<Long, String>() {
  41.       @Override
  42.       public String call(Long in) {
  43.         return "Received " + in + " flume events.";
  44.       }
  45.     }).print();

  46.     ssc.start();
  47.     ssc.awaitTermination();
  48.   }
  49. }
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Case study Count Event study Using received package events import should

本帖被以下文库推荐

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-28 23:35