Skip to content

Consume the last N messages from Pulsar #6523

Closed

Description

@terrencehan

In our product, we need to show the last N messages to users. While using Kafka, we could simply pull messages based on Offset. Is there an equivalent of method or API for Pulsar?

It seems we could only subscribe to a topic and try to move the cursor to some point based on messageId. But it hard to determine which messageId should be used, because messageId is not sequential.

Activity

  1. added
    type/feature
    on Mar 11, 2020
  2. codelipenghui commented on Mar 16, 2020

    @codelipenghui
    Contributor

    Yes, currently only support reset cursor by time or message ID. Maybe it needs to support reset cursor by messages count(e.g. last 100 messages) in Pulsar and since a message can be a batch message. If we want to reset to precise last 100 messages, This can be an expensive operation since the broker needs to get the message metadata and counting the number of messages.

  3. jiazhai commented on Mar 16, 2020

    @jiazhai
    Member

    @terrencehan Regarding MessageId, It could get from the produce.send or consumer.receive. Maybe reader api is more suitable for this case. 1), set reader init MessageId, 2) read N messages. the initial messageId maybe similar to the way how you get kafka Offset.

  4. carl297r commented on Mar 2, 2022

    @carl297r

    Is it possible to consume the last N messages in the special case where N is 1? Ie Just consume the last message that was already produced.

  5. lhotari commented on Mar 2, 2022

    @lhotari
    Member

    Is it possible to consume the last N messages in the special case where N is 1? Ie Just consume the last message that was already produced.

    Yes, that is possible.

  6. carl297r commented on Mar 2, 2022

    @carl297r

    How? Tried using a Reader with MessageId.latest and it does not receive the latest message already produced. It only receives the first message published after the creation of the reader.

  7. lhotari commented on Mar 2, 2022

    @lhotari
    Member

    How? Tried using a Reader with MessageId.latest and it does not send the latest message already produced. It only send the first message published after the creation of the reader.

    There's an open issue. However a workaround exists: #10483 (comment) . When using a reader you usually also need to configure a rentention policy. The user manual contains details about that.

  8. carl297r commented on Mar 2, 2022

    @carl297r

    How? Tried using a Reader with MessageId.latest and it does not send the latest message already produced. It only send the first message published after the creation of the reader.

    There's an open issue. However a workaround exists: #10483 (comment) . When using a reader you usually also need to configure a rentention policy. The user manual contains details about that.

    Thanks. That is the issue we have but the workaround is effective.

  9. tisonkun commented on Mar 11, 2023

    @tisonkun
    Member

    Closed as answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions