需要三步:

1.shell:往 1234 端口写数据

nc localhost 1234

2.shell: 启动flume服务

cd /usr/local2/flume/bin

./flume-ng agent --conf /usr/local2/flume/conf -f /usr/local2/flume/conf/flume-to-spark.conf  --name a1

3.IDEA:

import org.apache.spark.SparkConf
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming.flume.FlumeUtils
import org.apache.spark.streaming.{Seconds, StreamingContext} object DStream_Flume_source {
def main(args: Array[String]): Unit = {
val host="localhost"
val port=
val setIntervalTime=Seconds()
val sparkConf=new SparkConf().setAppName("flume 数据源").setMaster("local[2]")
val ssc=new StreamingContext(sparkConf,setIntervalTime)
val stream=FlumeUtils.createStream(ssc,host,port,StorageLevel.MEMORY_ONLY_SER_2)
stream.count().map(x=>"收到"+x+"个 flume events").print()
val words=stream.flatMap(x=>new String(x.event.getBody.array()).split(" ")).map(x=>(x,))
words.reduceByKey((x,y)=>x+y).print()
ssc.start()
ssc.awaitTermination()
} }

在IDEA中可以看到输入的数据,中文也可以照常显示

/usr/local2/flume/conf/flume-to-spark.conf:

     a1.sources = r1
a1.sinks = k1
a1.channels = c1 # Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = # Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = localhost
a1.sinks.k1.port = # Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = # Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

注意整个启动顺序:IDEA>>>>shell2>>>>shell1 否则报错

IDEA Spark Streaming Flume数据源 --解决无法转化为实际输入数据,及中文乱码(Scala)的更多相关文章

  1. Spark Streaming + Flume整合官网文档阅读及运行示例

    1,基于Flume的Push模式(Flume-style Push-based Approach)      Flume被用于在Flume agents之间推送数据.在这种方式下,Spark Stre ...

  2. <Spark Streaming><Flume><Integration>

    Overview Flume:一个分布式的,可靠的,可用的服务,用于有效地收集.聚合.移动大规模日志数据 我们搭建一个flume + Spark Streaming的平台来从Flume获取数据,并处理 ...

  3. 解决ubuntu中zip解压的中文乱码问题

    转自解决ubuntu中zip解压的中文乱码问题 在我的ubuntu12.10中,发现显示中文基本都是正常的,只有在解压windows传过来的zip文件时,才会出现乱码.所以,我用另一个方法解决中文乱码 ...

  4. php函数:解决数组转对象时数组内中文乱码问题

    function to_urlencode(&$arr){//解决数组转对象时数组内中文乱码问题 foreach($arr as $key => $value){ if(is_array ...

  5. 解决springmvc使用ResponseBody注解返回json中文乱码问题

    spring版本:4.2.5.RELEASE 查看“org.springframework.http.converter.StringHttpMessageConverter”源码,中有一段说明: B ...

  6. 解决loadrunner 脚本和replaylog中的中文乱码问题

    解决loadrunner 脚本和replaylog中的中文乱码问题 解决这个问题必须认识到一个事实就是,loadrunner和测试服务器交换数据使用的是utf8格式,但是展现在replaylog中是使 ...

  7. 解决docker容器中Centos7系统的中文乱码

    解决docker容器中Centos7系统的中文乱码问题有如下两种方案: 第一种只能临时解决中文乱码: 在命令行中执行如下命令: # localedef -i zh_CN -f UTF-8 zh_CN. ...

  8. 解决springboot序列化 json数据到前端中文乱码问题

    前言 关于springboot乱码的问题,之前有文章已经介绍过了,这一篇算是作为补充,重点解决对象在序列化过程中出现的中文乱码的问题,以及后台报500的错误. 问题描述 spring Boot 中文返 ...

  9. IDEA Spark Streaming Kafka数据源-Consumer

    import org.apache.spark.SparkConf import org.apache.spark.streaming.kafka.KafkaUtils import org.apac ...

随机推荐

  1. Java运算符法则

    JAVA运算符法则 运算符是一种特殊的符号,用于表示数据的运算,赋值和比较等: 算术运算符 正号+,负号-,加+,减-,乘*,除/,余或取模%,自增++,自减--,字符串相加+ 正号负号运算符代表运算 ...

  2. EasyUI_datagrid

    案例一丶jquery.easyui.min.js:10631 Uncaught TypeError: this.renderEmptyRow is not a function 解决方法:datagr ...

  3. 模板—AC自动机

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; struct ...

  4. Python,subprocess模块(补充)

    1.subprocess模块,前戏 res = os.system('dir') 打印到屏幕,res为0或非0 os.popen('dir') 返回一个内存对象,相当于文件流 a = os.popen ...

  5. tomcat7解决jsp参数传递的中文乱码问题

    解决jsp参数传递的中文乱码问题 制作人:全心全意 在jsp页面中,通过参数传递传递中文时,在显示参数值时中文内容变成了乱码.这是因为请求参数的文字编码方式与页面中的不一致造成的,所有的request ...

  6. web视频播放插件:Video For Everybody

    相比其它的web视频播放插件(video.js , jwplayer等)来说,Video For Everybody(极力推荐)是一款更好的视频播放插件,无需任何下载,支持html5以及flash播放 ...

  7. 第十二节:Web爬虫之MongoDB数据库安装与数据存储

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功 ...

  8. java,有用的代码片段

    在我们写程序的过程中,往往会经常遇到一些常见的功能.而这些功能或效果往往也是相似的,解决方案也相似.下面是我在写代码的过程中总结的一些有用的代码片段. 1.在多线程环境中操作同一个Collection ...

  9. SHA256兼容性

    SHA-2是一个加密哈希(Cryptographic Hash)函数的一个集合,包括SHA-224,SHA256和SHA-512.在SHA-256中的256代表哈希(Hash)输出或者摘要的位尺寸(即 ...

  10. Java Web学习总结(30)——Service层在MVC框架中的意义和职责

    mvc框架由model,view,controller组成,执行流程一般是:在controller访问model获取数据,通过view渲染页面. mvc模式是web开发中的基础模式,采用的是分层设计, ...