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

Negative acknowledge doesn't work with message_id #178

Closed
Samreay opened this issue Dec 21, 2023 · 2 comments · Fixed by #180
Closed

Negative acknowledge doesn't work with message_id #178

Samreay opened this issue Dec 21, 2023 · 2 comments · Fixed by #180
Assignees

Comments

@Samreay
Copy link

Samreay commented Dec 21, 2023

The docs state:

    def negative_acknowledge(self, message):
        """
        Acknowledge the failure to process a single message.

        When a message is "negatively acked" it will be marked for redelivery after
        some fixed delay. The delay is configurable when constructing the consumer
        with {@link ConsumerConfiguration#setNegativeAckRedeliveryDelayMs}.

        This call is not blocking.

        Parameters
        ----------

        message:
            The received message or message id.
        """

Specifically, that you can pass either the message or the message id into the function. However, I don't believe this is correct, and passing the message id does not work. To reproduce this issue, first run a local pulsar standalone instance, via

docker run -it -p 6650:6650 -p 8080:8080 --tmpfs /pulsar/data apachepulsar/pulsar:3.1.0 bin/pulsar standalone

And then run the following code:

import pulsar

client = pulsar.Client("pulsar://localhost:6650")
producer = client.create_producer("persistent://public/default/tmp_example")
consumer = client.subscribe("persistent://public/default/tmp_example", "sub", negative_ack_redelivery_delay_ms=10)
producer.send(b"hello")
while True:
    msg = consumer.receive()
    message_id = msg.message_id()
    print(msg, message_id)
    # consumer.negative_acknowledge(msg) # This works and causes redelivery
    consumer.negative_acknowledge(msg.message_id())  # This does not cause redelivery

When you pass in the message_id, no redeliveries occur. When you comment out the last line and swap to passing in the message as a whole, redeliveries occur.

Why using the message id matters: Our services consume the pulsar messages and convert them into non-pulsar structures (like pydantic objects or other python classes). We attach the message id to those objects so we can ack/nack them as needed without storing the entire original pulsar message

I suspect the general acknowledge method has the same bug in it.

@BewareMyPower
Copy link
Contributor

Yeah it's a bug that acknowledge also has the same issue.

if isinstance(message, Message):

We should check more types here.

@BewareMyPower BewareMyPower self-assigned this Dec 25, 2023
@BewareMyPower
Copy link
Contributor

Oh, it's not the issue with type checking. It's a regression that was introduced by #121.

image

I will push a fix ASAP and include it in the incoming 3.4.0 release.

BewareMyPower added a commit to BewareMyPower/pulsar-client-python that referenced this issue Dec 25, 2023
Fixes apache#178

### Motivation

apache#121 introduces a
regression that when `negative_acknowledge` accepts a message ID, the
underlying `acknowledgeAsync` method will be called.

### Modifications

Fix the `Consumer_negative_acknowledge_message_id` method and add the
test for negative acknowledging message IDs in `test_redelivery_count`.
BewareMyPower added a commit that referenced this issue Dec 26, 2023
Fixes #178

### Motivation

#121 introduces a
regression that when `negative_acknowledge` accepts a message ID, the
underlying `acknowledgeAsync` method will be called.

### Modifications

Fix the `Consumer_negative_acknowledge_message_id` method and add the
test for negative acknowledging message IDs in `test_redelivery_count`.
RobertIndie pushed a commit that referenced this issue Dec 26, 2023
Fixes #178

### Motivation

#121 introduces a
regression that when `negative_acknowledge` accepts a message ID, the
underlying `acknowledgeAsync` method will be called.

### Modifications

Fix the `Consumer_negative_acknowledge_message_id` method and add the
test for negative acknowledging message IDs in `test_redelivery_count`.

(cherry picked from commit b9c7219)
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

Successfully merging a pull request may close this issue.

2 participants