I am new to Vert.x and trying to create verticle using scala. While I am sending a message from vertx using eventbus, but message is not received by handler. Following is my code:
class HelloWorldEventBusVerticle extends ScalaVerticle {
override def startFuture(): Future[_] = {
vertx
.eventBus()
.consumer[String]("com.harmeetsingh13.verticle")
.handler { msg =>
println(s"Message Body ${msg.body()}")
msg.body() match {
case user: String => println(s"Hello $user!! message")
}
}
.completionFuture()
}
}
object HelloWorldEventBusVerticle extends App {
val vertex = Vertx.vertx()
vertex.deployVerticleFuture(ScalaVerticle.nameForVerticle[HelloWorldEventBusVerticle]).onComplete {
case Success(result) => println(s"Deployment Id is : ${result}")
case Failure(cause) => cause.printStackTrace()
}
vertex.eventBus()
.send("com.harmeetsingh13.verticle", "James")
}
What is the problem with this code ?
Update
While I am adding vertex.eventBus().send("com.harmeetsingh13.verticle", "James")
in Future onComplete
method. In that case, the event bus received the message successfully. But when, I am using following below code, the event handler will not able to receive the message.
vertex.deployVerticle(ScalaVerticle.nameForVerticle[HelloWorldEventBusVerticle])
vertex.eventBus().send("com.harmeetsingh13.verticle", "James")