简体   繁体   English

将数据流从VM套接字/远程套接字发送到在主机OS上运行的Flink程序

[英]send dataStream from VM socket / remote socket to Flink program running on Host OS

As mentioned in Flink documentation, I was able to read text input from text server by opening a local socket using 如Flink文档中所述,我能够通过使用以下命令打开本地套接字来读取来自文本服务器的文本输入:

amar@admin:~$ nc -l 12345

and then receiving it on Flink program using 然后使用Flink程序接收它

DataStream<String> text = env.socketTextStream("localhost", 12345);

text.print();

env.execute();

However, as I am simulating some scenario, so I want to get Stream of Data from a VM (and then various VM's eventually) and send it to CEP program running on Host OS. 但是,由于我正在模拟某些场景,因此我想从VM(然后是各种VM)获取数据流,并将其发送到在主机OS上运行的CEP程序。

So, I have installed VM, using Vagrant and SSH into it using vagrant ssh 所以,我已经安装了VM,使用Vagrant和SSH使用vagrant ssh将其安装到其中

  1. the hostname of guest OS is precise64 来宾操作系统的主机名是precision64

  2. IP address using ifconfig = 10.0.2.15 使用ifconfig = 10.0.2.15的IP地址

Now, what I want to do, for now, is to see if I can send some data from VM and receive it in Flink program the same way I was able to do in the local environment. 现在,我现在想要做的是看是否可以像在本地环境中一样从VM发送一些数据并在Flink程序中接收它们。

I opened Netcat socket on guest os by using 我通过使用在来宾操作系统上打开了Netcat套接字

vagrant@precise64:~$ nc -l 12345

and I tried to receive it on host program by using, but got error 我试图通过使用在主机程序上接收它,但出现错误

DataStream<String> text = env.socketTextStream("precise64", 12345);

text.print();

env.execute();

I also tried precise64@10.0.2.15 above, but I think I am doing it wrong. 我也在上面尝试了precision64@10.0.2.15,但我认为我做错了。

any ideas, how should I approach to send DataStream from VM to Host Flink Program 任何想法,我应该如何将数据流从VM发送到Host Flink程序

Suggestions are most welcome, thanks in advance! 建议是最欢迎的,在此先感谢!

You could try this: 您可以尝试以下方法:

1.Program: 1.Program:

import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.time.Time

object WindowWordCount {
  def main(args: Array[String]) {

    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val text = env.socketTextStream("localhost", 9999)

    val counts = text.flatMap { _.toLowerCase.split("\\W+") filter { _.nonEmpty } }
      .map { (_, 1) }
      .keyBy(0)
      .timeWindow(Time.seconds(5))
      .sum(1)

    counts.print

    env.execute("Window Stream WordCount")
  }
}

2.After ran the above program.You could start this. 2.运行完上述程序后,就可以启动了。

nc -lk 9999

This will work. 这将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM