pulsar-client-node icon indicating copy to clipboard operation
pulsar-client-node copied to clipboard

Creating a subscription with initial position as "earliest"

Open goku321 opened this issue 5 years ago • 3 comments

My use case: I have a shared subscription with a bunch of consumers. Suppose, all the consumers die and there are messages still being published to the topic. When a new consumer comes in, I want it to read from the last unacknowledged message so that no messages are lost or unprocessed.

So, I want to create a subscription with initial subscription position as earliest but I don't see any option to set the initial position. Also, What is default behavior? earliest or latest ?

goku321 avatar May 29 '20 14:05 goku321

Since subscription hold cursor(position of acked message) and cursor move forward when consumer send acknowledge, I think new consumer just reconnect your shared subscription.

More detail, please see below. https://pulsar.apache.org/docs/en/concepts-messaging/#shared

equanz avatar Jun 03 '20 08:06 equanz

@equanz What if the topic had messages even before creating the subscription? I don't think subscription will read the old messages by default.

goku321 avatar Jun 03 '20 12:06 goku321

I see. In your use case, create new subscription when a new consumer comes in, right? If so, I think new subscription use earliest position and don't process processed message by consumer side.

earliest can set initial subscription position to 'never deleted' message. However, 'never deleted' message is not always corresponding to unacked message correctly.

If you don't implement this process, I think you should reuse subscription.

equanz avatar Jun 04 '20 08:06 equanz