Bird
Raised Fist0
RabbitMQdevops~10 mins

Message acknowledgment in RabbitMQ - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to acknowledge a message in RabbitMQ using the channel.

RabbitMQ
channel.[1](delivery_tag=method.delivery_tag)
Drag options to blanks, or click blank then click option'
Areject
Bconsume
Cbasic_nack
Dbasic_ack
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reject' instead of 'basic_ack' causes the message to be rejected.
Using 'consume' is for receiving messages, not acknowledging.
2fill in blank
medium

Complete the code to reject a message and requeue it in RabbitMQ.

RabbitMQ
channel.basic_reject(delivery_tag=method.delivery_tag, requeue=[1])
Drag options to blanks, or click blank then click option'
ATrue
BNone
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using False will discard the message instead of requeuing.
Using None causes a type error.
3fill in blank
hard

Fix the error in the code to negatively acknowledge multiple messages at once.

RabbitMQ
channel.basic_nack(delivery_tag=method.delivery_tag, multiple=[1])
Drag options to blanks, or click blank then click option'
ATrue
BNone
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using False only nacks a single message.
Using None causes a type error.
4fill in blank
hard

Fill both blanks to consume messages with manual acknowledgment enabled.

RabbitMQ
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[1], [2]='task_queue')
Drag options to blanks, or click blank then click option'
AFalse
BTrue
Cqueue
Dconsumer_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Setting auto_ack=True disables manual ack.
Using queue instead of consumer_tag for the second blank.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters messages with priority greater than 5 and acknowledges them.

RabbitMQ
acknowledged = {msg_id:priority for msg_id, priority in messages.items() if priority [1] 5 and channel.basic_ack(delivery_tag=[2])}
Drag options to blanks, or click blank then click option'
A:
B>
Cmsg_id
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using ',' instead of ':' in dictionary comprehension.
Using '<' instead of '>' for filtering priority.
Using wrong variable name for delivery tag.

Practice

(1/5)
1. What is the main purpose of message acknowledgment in RabbitMQ?
easy
A. To confirm that a message was received and processed successfully
B. To delete the message queue permanently
C. To create a new message exchange
D. To encrypt messages before sending

Solution

  1. Step 1: Understand message acknowledgment role

    Message acknowledgment tells RabbitMQ that the consumer has processed the message successfully.
  2. Step 2: Identify the purpose from options

    Only To confirm that a message was received and processed successfully describes confirming message processing, which prevents message loss.
  3. Final Answer:

    To confirm that a message was received and processed successfully -> Option A
  4. Quick Check:

    Message acknowledgment = Confirm processing [OK]
Hint: Acknowledgment means confirming message processed [OK]
Common Mistakes:
  • Confusing acknowledgment with queue deletion
  • Thinking acknowledgment creates exchanges
  • Assuming acknowledgment encrypts messages
2. Which RabbitMQ client method is used to acknowledge a message after processing?
easy
A. basic_reject
B. basic_publish
C. basic_consume
D. basic_ack

Solution

  1. Step 1: Recall RabbitMQ acknowledgment method

    The method to acknowledge a message is basic_ack, which confirms message processing.
  2. Step 2: Match method to options

    Only basic_ack matches the acknowledgment method; others are for publishing, consuming, or rejecting.
  3. Final Answer:

    basic_ack -> Option D
  4. Quick Check:

    basic_ack = acknowledge message [OK]
Hint: Use basic_ack to confirm message processed [OK]
Common Mistakes:
  • Using basic_publish to acknowledge
  • Confusing basic_consume with acknowledgment
  • Mistaking basic_reject as acknowledgment
3. Given this Python snippet using pika:
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=False)

def callback(ch, method, properties, body):
    print(f"Received {body}")
    ch.basic_ack(delivery_tag=method.delivery_tag)
What will happen if basic_ack is not called inside callback?
medium
A. Messages will be lost after delivery
B. Messages will be automatically acknowledged
C. Messages will be requeued and redelivered
D. The queue will be deleted

Solution

  1. Step 1: Understand auto_ack=False effect

    With auto_ack=False, messages must be manually acknowledged or they stay unacknowledged.
  2. Step 2: Consequence of missing basic_ack

    If basic_ack is not called, RabbitMQ will requeue the message and redeliver it to consumers.
  3. Final Answer:

    Messages will be requeued and redelivered -> Option C
  4. Quick Check:

    No ack + auto_ack=False = redelivery [OK]
Hint: No ack with auto_ack false causes redelivery [OK]
Common Mistakes:
  • Assuming messages are lost without ack
  • Thinking messages auto-acknowledge without basic_ack
  • Believing queue deletes on missing ack
4. You wrote this callback in Python with pika:
def callback(ch, method, properties, body):
    print(f"Processing {body}")
    ch.basic_ack(delivery_tag=method.delivery_tag + 1)
What is the problem with this acknowledgment call?
medium
A. The delivery tag is incorrect, causing ack failure
B. basic_ack does not accept delivery_tag parameter
C. The callback function is missing required parameters
D. basic_ack should be called before processing the message

Solution

  1. Step 1: Check delivery_tag usage

    The delivery tag must match the exact tag from method.delivery_tag to acknowledge the correct message.
  2. Step 2: Identify error in delivery_tag calculation

    Adding 1 to the delivery tag sends an invalid tag, so RabbitMQ will not acknowledge the message properly.
  3. Final Answer:

    The delivery tag is incorrect, causing ack failure -> Option A
  4. Quick Check:

    delivery_tag must match exactly [OK]
Hint: Use exact delivery_tag value for ack [OK]
Common Mistakes:
  • Modifying delivery_tag before ack
  • Thinking basic_ack lacks delivery_tag parameter
  • Calling ack before processing message
5. You want to ensure that if your consumer crashes before acknowledging, the message is redelivered. Which combination of settings and code achieves this safely?
hard
A. Set auto_ack=True and call basic_ack in callback
B. Set auto_ack=False and call basic_ack with correct delivery_tag after processing
C. Set auto_ack=False and never call basic_ack
D. Set auto_ack=True and never call basic_ack

Solution

  1. Step 1: Understand auto_ack impact on message safety

    Setting auto_ack=True acknowledges messages immediately, risking message loss if consumer crashes.
  2. Step 2: Use manual acknowledgment for safe processing

    Setting auto_ack=False and calling basic_ack after processing ensures messages are only removed after success.
  3. Step 3: Confirm correct delivery_tag usage

    Calling basic_ack with the exact delivery tag confirms the message was processed and prevents redelivery.
  4. Final Answer:

    Set auto_ack=False and call basic_ack with correct delivery_tag after processing -> Option B
  5. Quick Check:

    Manual ack + correct tag = safe redelivery [OK]
Hint: Use manual ack with correct tag for safe redelivery [OK]
Common Mistakes:
  • Using auto_ack=True for critical messages
  • Not calling basic_ack at all
  • Calling basic_ack with wrong delivery_tag
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard