Apache Pulsar's APIs (https://pulsar.apache.org/api/client/org/apache/pulsar/client/api/Consumer.html) include at least two methods of consuming messages from a Pulsar topic/queue:
- Using Consumer.receive() (or Consumer.receiveAsync())
- Using ConsumerBuilder.messageListener(MessageListener messageListener) to add a message listener, which sends a reference to the Consumer and Message to an instance of a MessageListener
Mostly it feels like these are on equal ground, and the event-like methodology of using a MessageListener makes sense, except that the Consumer object has other methods that I find might be useful in a controlled while-loop, such as: isConnected(), receiveAsync(), pause(), resume(), and seek(MessageId messageId).
With these additional features in the Consumer class, even though the Consumer is passed into the MessageListener, why not have a simple loop for the consumer instead of using a single MessageListener?
Is there an advantage or preference to using MessageListener in Pulsar, or is this just an option given to the developer?
In the past I've mostly written consumer loops for JMS and Kafka.