Spark streaming doesn't receive any data from readStream,socket

Viewed 12

Currently, I'm streaming tweets via API using spark & tweepy,

It should be sending the tweets (live data) into socket enter image description here

send_tweet.py
if __name__ == "__main__":
    # server (local machine) creates listening socket
    s = socket.socket()
    host = "127.0.0.1"    
    port = 2566
    s.bind((host, port))
    print('socket is ready')
    # server (local machine) listens for connections
    s.listen(4)
    print('socket is listening')
    # return the socket and the address on the other side of the connection (client side)
    c_socket, addr = s.accept()
    print("Received request from: " + str(addr))
    # select here the keyword for the tweet data
    sendData(c_socket, keyword = ['piano'])

But, after executing the preprocessing script, the socket doesn't receive any tweets (live data) . enter image description here

preprocessing.py
lines = spark.readStream.format("socket").option("host", "127.0.0.1").option("port", 2566).load()

After running the command above, The send_tweet.py should be accepting the request by now.

Port already has been exposed in docker-compose.

However, on a seperate try and error case, I've already used curl/nc to execute, and it was successful; they were able to receive the request.

Main problem is when I use Spark to send the data, it does not work. But the port was running.

I've also adjusted the ip, the problem still persist.

lines = spark.readStream.format("socket").option("host", "10.32.2.9").option("port", 2566).load()
lines = spark.readStream.format("socket").option("host", "localhost").option("port", 2566).load()

I've also tweaked the following config for spark.

    spark = SparkSession.builder.master('spark://spark-master:7077')\
        .appName("TwitterSentimentAnalysisPolarity")\
        .enableHiveSupport()\
        .getOrCreate()
    spark = SparkSession.builder.master('local[1]')\
        .appName("TwitterSentimentAnalysisPolarity")\ 
        .getOrCreate()

Any idea where I got this wrong?

Currently, I'm referring to this website

0 Answers
Related