【问题标题】:How to load Flink Streaming data from Zeppelin如何从 Zeppelin 加载 Flink Streaming 数据
【发布时间】:2017-10-27 02:53:05
【问题描述】:

我开始在 Zeppelin 上使用 Flink,并尝试在流媒体中运行最简单的程序:wordcount。 当我使用终端在本地模式下运行此代码时,它可以工作。

我是这样做的:https://ci.apache.org/projects/flink/flink-docs-release-1.2/quickstart/setup_quickstart.html

这是代码:

object SocketWindowWordCount {

  /** Main program method */
  def main(args: Array[String]) : Unit = {

    // the host and the port to connect to
    var hostname: String = "localhost"
    var port: Int = 0

    try {
      val params = ParameterTool.fromArgs(args)
      hostname = if (params.has("hostname")) params.get("hostname") else "localhost"va
      port = params.getInt("port")
    } catch {
      case e: Exception => {
        System.err.println("No port specified. Please run 'SocketWindowWordCount " +
          "--hostname <hostname> --port <port>', where hostname (localhost by default) and port " +
          "is the address of the text server")
        System.err.println("To start a simple text server, run 'netcat -l <port>' " +
          "and type the input text into the command line")
        return
      }
    }

    // get the execution environment
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    // get input data by connecting to the socket
    val text = env.socketTextStream(hostname, port, '\n')

    // parse the data, group it, window it, and aggregate the counts 
    val windowCounts = text
          .flatMap { w => w.split("\\s") }
          .map { w => WordWithCount(w, 1) }
          .keyBy("word")
          .timeWindow(Time.seconds(5))
          .sum("count")

    // print the results with a single thread, rather than in parallel
    windowCounts.print().setParallelism(1)

    env.execute("Socket Window WordCount")
  }

  /** Data type for words with count */
  case class WordWithCount(word: String, count: Long)
}

但是,当我尝试在 Zeppelin 上运行此代码时……我不知道该怎么做。 我想我也需要在终端中打开一个套接字,但我不知道如何让 Flink 与这个端口连接。我应该在 Flink 上打开几个窗口吗?

我可以总结以下问题:如何从 Zeppelin 加载 flink 流数据???

我需要在最后添加一些 Scala 方法,例如:

import scala.io.Source

val programRunning = Source.from"Socket"...?

提前感谢您的帮助! :)

【问题讨论】:

标签: scala apache-flink apache-zeppelin flink-streaming


【解决方案1】:

在终端中,你可以使用

nc -lk 9999

建立一个绑定到端口 9999 的服务,它将在标准输入上接收到的任何内容发送给它的客户端。

Apache Zeppelin: A friendlier way to Flink 也可能会有所帮助。

【讨论】:

  • 非常感谢文档非常有用,解决了我的问题!
猜你喜欢
  • 1970-01-01
  • 2017-11-01
  • 2018-09-13
  • 1970-01-01
  • 2020-07-15
  • 2018-01-09
  • 2016-12-05
  • 1970-01-01
  • 2021-11-01
相关资源
最近更新 更多