0

I am working on a scala application in which I am using kafka. I want to retrieve topic names from my code. My code is as follows:

  def getTopic = {
    metadataClient.listTopics().map(x => logger.info(s"topic - $x"))
  }

And I am calling this method from my main class. On running it is not giving any errors. But When I call this method and store result in a val and print it. it says Future(<not completed>). Also it is not printing value of x. How can I correct it.

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
  • I guess you're using `alpakka-kafka` right? `MetadataClient` offers this `listTopics` function that's `asynchronous`, meaning it'll return the result wrapped in a `Future` (specifically `Future[Map[String, List[PartitionInfo]]]`. Have a look at how to deal with Futures here: https://docs.scala-lang.org/overviews/core/futures.html – mfirry Jul 15 '20 at 07:40
  • yes I am using alpakka-kafka –  Jul 15 '20 at 07:43
  • how can I get result? @mfirry –  Jul 15 '20 at 07:46
  • Have a look at alpakka-kafka samples: https://github.com/akka/alpakka-samples/blob/master/alpakka-sample-http-csv-to-kafka/step_007_produce_to_kafka/src/main/scala/samples/Main.scala – mfirry Jul 15 '20 at 08:41

0 Answers0