Spark Streaming处理File Streams

File Streams
官网:http://spark.apache.org/docs/latest/streaming-programming-guide.html
File Streams文件流
Streaming文件是moving过来的

IDEA源码:

/**
   * Create an input stream that monitors a Hadoop-compatible filesystem
   * for new files and reads them using the given key-value types and input format.
   * Files must be written to the monitored directory by "moving" them from another
   * location within the same file system. File names starting with . are ignored.

没有jop0一直在跑的
File streams do not require running a receiver so there is no need to allocate(分配) any cores for receiving file data.

文件流不需要运行一个接收机,所以不需要分配(分配)任何核心接收文件数据。

ssc.textFileStream("hsfs://hadoop:8020/spark/log")

这里要注意:
时间一:本应用程序启动的时间
时间二:指定hafs上的目录下的文件的时间
默认是只会读取时间一》时间二的时间
如果你文件的时间在启动时间之后,不好意思 不认
因为:
A file is considered part of a time period based on its modification(修改) time, not its creation(创造) time.
如果你启动之后,放进去的数据,启动之后的你创建的数据是没有问题的,如果你的数据文件的时间在你启动之前,这个数据是不认的
文件这种处理方式是不实用的,因为这种偏移量很难搞定,生产上可以用,但是不比kafka,需要各种各样的东西,自己来维护
我们原来怎么办
都是把你处理以后把你的时间,丢到一个集合里面去,代码里面把这个偏移量管理起来,当你挂掉以后,从这里面来取

猜你喜欢

转载自blog.csdn.net/qq_43688472/article/details/86614163