question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

basic_get with explicit no_ack=True, ack message, it should not

See original GitHub issue

Hey

The following example below auto ack message - rabbitmq receive a get auto_auto ack whereas it should receive get manual_ack. Until I do not call myself ack the message should stay in the queue.

channel init :

        connection:pika.BlockingConnection = pika.BlockingConnection(pika.URLParameters(amqp_url))

        self._channel:BlockingChannel = connection.channel()
        self._channel.confirm_delivery()
        self._channel.queue_declare(queue=self._queue, durable=True, passive=True, auto_delete=False)
        while(True):
            method_frame, header_frame, body = self._channel.basic_get(queue=self._queue, no_ack=True)

Here the result payload of my debug :

rabbit-error

b’\x00<\x00F’, b’\x00\x00’, b’\x1f’, b’el.support.destination.ingester’, b’\x01’ marshal result : b"\x01\x00\x01\x00\x00\x00’\x00<\x00F\x00\x00\x1fel.support.destination.ingester\x01\xce"

What’s the problem ? or what i’m doing wrong ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukebakkencommented, Sep 17, 2018

no_ack=True indicates that the message does not require an acknowledgement and will be instantly acknowledged on delivery. You should use no_ack=False if you need to manually ack messages.

confirm_delivery turns on publisher confirms, which is a different feature.

Please see the documentation here:

https://www.rabbitmq.com/confirms.html

0reactions
deeplearningboycommented, Mar 24, 2021

here is fix

import pika

class RabbitMQ(): def init(self): connection = pika.BlockingConnection() self.channel = connection.channel() # del connection self.channel.confirm_delivery() self.body = None

def publish(self, routing_key, body, exchange='' ):
    try:
        self.channel.basic_publish(
            exchange=exchange,
            routing_key=routing_key,
            body=body)
    except Exception as ex:
        print('Error Message could not be confirmed: ' + ex.args[0])
        print(f'Message [{exchange}] [{routing_key}] [{body}]')

def get_data(self, queue ):
    data = []
    while True:
        method_frame, header_frame, body = self.channel.basic_get( queue )
        if method_frame:
            data.append( body )
        else:
            return data

def close(self):
    self.channel.stop_consuming()
    self.channel.connection.close()

if name == ‘main’: rabbit = RabbitMQ() for i in range(6): rabbit.publish(‘test’,f’Hello World! {i}')

Read more comments on GitHub >

github_iconTop Results From Across the Web

RabbitMQ Basic Recover Doesn't Work - Stack Overflow
Messages can be consumed in two ways noAck=false or noAck=true. noAck is a parameter on both Model.BasicConsume and Model.BasicGet.
Read more >
Consumer Acknowledgements and Publisher Confirms
Therefore, automatic message acknowledgement should be considered unsafe and not suitable for all workloads. Another thing that's important to consider when ...
Read more >
Channel - javadoc.io
While a Channel can be used by multiple threads, it's important to ensure that ... i.e. with explicit acks // some deliveries take...
Read more >
FAQ: RabbitMQ Basic Consumer vs. RabbitMQ Basic Get
The RabbitMQ client registers with the broker and waits for messages. Consumers can acknowledge receipt automatically and use a cancellation ...
Read more >
RabbitMQ Operation Timeout Exception in BasicGet
Impl.AutorecoveringModel.BasicGet(String queue, Boolean autoAck) When this error is occurring the message is not received in consumer and not acknowledged ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found