Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockRDD[14] at command122480944 while reading the data in Spark Scala [Databricks] #135

Open
vinayt704 opened this issue Jan 12, 2022 · 0 comments

Comments

@vinayt704
Copy link

Hello, Im trying to read data from rabbitmq in databricks. below is the code.

def onStart() {
// Start the thread that receives data over a connection
new Thread("Socket Receiver") {
override def run() { receive() }
}.start()
}

def onStop() {
// There is nothing much to do as the thread calling receive()
// is designed to stop by itself isStopped() returns false
}

/** Create a socket connection and receive data until receiver is stopped */
def receive() {
var socket: Socket = null
var userInput: String = null
try {

 var batchInterval = Seconds(5)
          var ssc = new StreamingContext(sc, batchInterval)
  val host = ""
            val port = ""
            val queueName = ""
            val vHost = ""
            val userName = ""
            val password = ""
  
    val receiverStream = RabbitMQUtils.createStream(ssc, Map(
  "host" -> "host",
  "port" -> "port",
  "queueName" -> "queueName",
  "vHost" -> "vHost",
  "userName" -> "userName",
  "password" -> "password"
      ))
 receiverStream .start()
   val lines = ssc.receiverStream(new CustomReceiver(host, port.toInt))

lines .foreachRDD(rdd => {
if (!rdd.isEmpty()) {
val count = rdd.count()
// Do something with this message
println(s"EVENTS COUNT : \t $count")
totalEvents.add(count)
//rdd.collect().sortBy(event => event.toInt).foreach(event => print(s"$event, "))
} else println("RDD is empty")
println(s"TOTAL EVENTS : \t $totalEvents")
})

  lines.print()
  ssc.start() 
  ssc.awaitTermination()

I either get empty output or BlockRDD[] issue. Did anyone face similar kind of issue. Could someone please assist.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant