使用 netcat 数据源测试 Flume
请对 Flume 的相关配置文件进行设置,从而可以实现如下功能:在一个 Linux 终端(这
里称为“Flume 终端”)中,启动 Flume,在另一个终端(这里称为“Telnet 终端”)中,
输入命令“telnet localhost 44444”,然后,在 Telnet 终端中输入任何字符,让这些字符可以
顺利地在 Flume 终端中显示出来。
mport sys from pyspark import SparkContext from pyspark.streaming import StreamingContext from pyspark.streaming.flume import FlumeUtils import pyspark if __name__ == "__main__": if len(sys.argv) != 3: print("Usage: flume_wordcount.py <hostname> <port>", file=sys.stderr) exit(-1) sc = SparkContext(appName="FlumeEventCount") ssc = StreamingContext(sc, 2) hostname = sys.argv[1] port = int(sys.argv[2]) stream = FlumeUtils.createStream(ssc, hostname, port, pyspark.StorageLevel.MEMORY_AND_DISK_SER_2) stream.count().map(lambda cnt: "Recieve " + str(cnt) + " Flume events!!!!").pprint() ssc.start() ssc.awaitTermination()
启动spark
运行flume
启动Telnet