Search code examples
apache-pulsar

Apache Pulsar Java client taking too much memory (OOM)


I wrote a simple Apache Pulsar client with Spring boot - a pulsar-producer initialized as beans that will be used in the rest controller to publish incoming api messages to Pulsar, and a consumer that consumes message, prints some values in console & acknowledge.

As of now the application is very simple, but the moment this spring-boot app loads I see memory peak, at times getting OOM. Is there any specific configuration to be used when using Pulsar client with Spring-boot?

The code is mostly the one found the Pulsar doc.


Solution

  • I am answering this to doc this issue - do not use the loops to consume messages, instead adopt the MessageListener subscribed to consumer via

    consumer.messageListener(new Myconsumer())

    or

    consumer.messageListener((consumer, msg)->{//do something})

    Docs didnt mention this, but I found surfing the consumer api.