在Flink Scala Shell中阅读来自Kafka的一些消息后如何停止?

时间:2019-03-12 10:00:13

标签: scala shell apache-kafka apache-flink flink-streaming

我正在将来自Kafka的消息读入Flink Scala shell。我想阅读一些消息,将其存储并停止。不想继续阅读。我可以阅读以下消息:

scala> val stream = senv.addSource(new FlinkKafkaConsumer011[String]("some-test-topic", new SimpleStringSchema(), properties)).print()
warning: there was one deprecation warning; re-run with -deprecation for details
stream: org.apache.flink.streaming.api.datastream.DataStreamSink[String] = org.apache.flink.streaming.api.datastream.DataStreamSink@3ba8ef4e

scala> senv.execute("Kafka Consumer Test")
Submitting job with JobID: 79b7380516b8ccb9ae71da29c97c8d8d. Waiting for job completion.
Connected to JobManager at Actor[akka.tcp://flink@localhost:55677/user/jobmanager#2006479320] with leader session id 00000000-0000-0000-0000-000000000000.
03/12/2019 15:15:16 Job execution switched to status RUNNING.
03/12/2019 15:15:16 Source: Custom Source -> Sink: Unnamed(1/1) switched to SCHEDULED 
03/12/2019 15:15:16 Source: Custom Source -> Sink: Unnamed(1/1) switched to DEPLOYING 
03/12/2019 15:15:16 Source: Custom Source -> Sink: Unnamed(1/1) switched to RUNNING 

如果不退出整个外壳程序,我将无法停止阅读消息。当我按Ctrl-C时,它会杀死作业以及外壳。我如何计时该过程,以便它读取一些消息并在一段时间后停止运行?可以在不退出外壳的情况下杀死它吗?

0 个答案:

没有答案