Search code examples
javaspringpulsar

how to remove the pulsar message from queue for a topic after message is consumed by a consumer application?


i have application which consumes topic from producer application using pulsar. i need a logic or some configuration to remove the messages from queue for a topic once it is consumed by my consumer application.Whenever my consumer application is restarted it gets all the messages in queue, even the previously received one


Solution

  • You are most likley not sending an acknowledgement that you have consumed the message successfully:

    Documentation states:

    Pulsar is built on the publish-subscribe pattern (often abbreviated to pub-sub). In this pattern, producers publish messages to topics; consumers subscribe to those topics, process incoming messages, and send acknowledgements to the broker when processing is finished.

    In order to acknowledge a message after consuming it, you do:

    consumer.acknowledge(msg);
    

    Reference: https://pulsar.apache.org/docs/concepts-messaging/#acknowledgement