0

How do you continually consume messages from Apache Pulsar using Akka Streams and print each message?

Below is sample code I found from the pulsar4s library. Instead of publishing the messages to another topic, how do you print the consumed messages?

val consumerFn = () => client.consumer(ConsumerConfig(Seq(intopic), Subscription("mysub")))
val producerFn = () => client.producer(ProducerConfig(outtopic))

val control = source(consumerFn, Some(MessageId.earliest))
                .map { consumerMessage => ProducerMessage(consumerMessage.data) }
                .to(sink(producerFn)).run()
Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
sreekesh.s
  • 158
  • 1
  • 8

1 Answers1

2

You can simply use Sink.foreach(println))

For example

source(consumerFn, Some(MessageId.earliest))
.runWith(Sink.foreach(println))
sreekesh.s
  • 158
  • 1
  • 8
iTech
  • 18,192
  • 4
  • 57
  • 80
  • On trying above solution i got no implicits found for parameter materializer. then added below code ``` source(consumerFn, Some(MessageId.earliest)) .runWith(Sink.foreach[String](println)) ``` now getting type mismatch. Can you please help me by providing a small code snippet to consume message. from pulsar using scala – sreekesh.s Jun 01 '20 at 12:43