with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
dispatcher = conn.sendall
consumer = Consumer(dispatcher)
try:
    consumer.run()
except Exception as e:
    consumer.stop()
s.close()
How to implement a RabbitMQ consumer using Pyspark Streaming module?