1

When I create the consumer

consumer = pulsar.Client(
            PULSAR_URL,
            authentication=AuthenticationOauth2(params)
        ).subscribe(
            topic=PULSAR_TOPIC,
            subscription_name=PULSAR_SUBSCRIPTION_NAME
        )

I cannot read all messages from the beginning, or all non read messages, I only can read messages created after the consumer is created.

The questions is about how can I set the consumer in order to read all non read messages previously.

Thanks

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

1 Answers1

1

You can specify the initial_position in the subscribe method to set the initial position of a consumer when subscribing to the topic. It could be either: InitialPosition.Earliest or InitialPosition.Latest. Default: Latest

So in your case, if you wanted to start at the oldest available message then you would want something like:

consumer = pulsar.Client(
        PULSAR_URL,
        authentication=AuthenticationOauth2(params)
    ).subscribe(
        topic=PULSAR_TOPIC,
        subscription_name=PULSAR_SUBSCRIPTION_NAME,
        initial_position=InitialPosition.Earliest
    )

Hope this helps!

David Kjerrumgaard
  • 1,056
  • 7
  • 10
  • 1
    Perhaps it would be worth also mentioning Pulsar's retention policy and the impact of using the default retention policy? – Lari Hotari Apr 07 '22 at 07:59