Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for ack #359

Open
taefed opened this issue Dec 11, 2023 · 3 comments
Open

Waiting for ack #359

taefed opened this issue Dec 11, 2023 · 3 comments

Comments

@taefed
Copy link

taefed commented Dec 11, 2023

I'm trying to consume 1 message at a time, and i'm acknowledging the message outside of the listener. But it's just grabbing the next message without waiting for the ack.

code sample:

let msg;
let msgConsumer;

const consumer = client.subscribe({
                    topic: `persistent://public/default/test1`,
                    subscription: `sub1`,
                    subscriptionType: 'Exclusive',
                    receiverQueueSize:0,
                    ackTimeoutMs:300000,
                    listener: (msg,msgConsumer) => {
                        console.log(msg.getData().toString());
                        msg = msg;
                        msgConsumer = msgConsumer;

                    }
                  });
                  
function someWhereElse(){

    msgConsumer.acknowledge(msg);


}

Is something like this possible?

@kimula
Copy link

kimula commented Dec 26, 2023

Since listener is used for asynchronous message processing, it doesn't seem to meet your requirement (1 message at a time).

  • Why are you using listener?
  • Could you try receive() instead? e.g.
const consumer = client.subscribe( /* without listener */ );

async function somewhereElse() {
  const msg = await consumer.receive();
  consumer.acknowledge(msg);
}

@taefed
Copy link
Author

taefed commented Dec 29, 2023

Thanks a lot for the response.

I'm not receiving in the same place I'm acknowledging. I'm trying to find a way to make 1 process add jobs to queues, and acknowledge them, and the other process needs to just process 1 at a time and wait for acknowledgement.

  1. process 1 adds a message to the queue.
  2. process 2 starts processing message
  3. process 1 acknowledges message
  4. process 2 can receive next message

if a second message gets added to the queue, it has to wait for the first message to be acknowledged,
I haven't found a way to make this work with the manual receive(). But I'm new to queueing so maybe I'm looking over something.

@equanz
Copy link
Contributor

equanz commented Jan 25, 2024

I'm trying to find a way to make 1 process add jobs to queues, and acknowledge them, and the other process needs to just process 1 at a time and wait for acknowledgement.

It seems we can't implement it with only the functionality of pulsar-client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants