【发布时间】:2020-04-27 03:17:58
【问题描述】:
我是 Apache Spark Streaming 的新手。我正在开发一个火花流应用程序来找到最短路径并将路径再次发送回客户端。我已经编写了用于获取数据并使用函数对其进行处理的代码,但是我遇到了一个问题,如何将结果再次发送回客户端 这是我的代码:
import networkx as nx
from pyspark import SparkConf,SparkContext
from pyspark.streaming import StreamingContext
TCP_IP = "127.0.0.1"
TCP_PORT = 5000
# Creating a Spark Configuration
conf=SparkConf()
conf.setAppName('ShortestPathApp')
sc= SparkContext(conf)
ssc= StreamingContext(sc,2)
def shortestPath(line):
# get the values from rdd
vehicleId = line[0]
source = line[1]
destination = line[2]
deadline = line[3]
# find shortest path
shortest = nx.dijkstra_path(G, source, destination)
# receive from Socket
dataStream =ssc.socketTextStream(TCP_IP,TCP_PORT)
vehicle_data = dataStream.map(lambda line: line.split(" "))
vehicle_data.foreachRDD(lambda rdd: rdd.foreach(shortestPath))
ssc.start()
ssc.awaitTermination()
如何将数据发送回客户端
【问题讨论】:
-
是否要将数据发送回客户端的 TCP 套接字?
-
是的@QuickSilver
标签: python python-3.x apache-spark pyspark spark-streaming