Bird
Raised Fist0
RabbitMQdevops~10 mins

Publisher confirms 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 enable publisher confirms on the channel.

RabbitMQ
channel.[1]()
Drag options to blanks, or click blank then click option'
Aconfirm_select
Bset_confirm
Cstart_confirm
Denable_confirm
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like 'start_confirm'.
Trying to enable confirms on the connection instead of the channel.
2fill in blank
medium

Complete the code to publish a message and wait for confirmation.

RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body='Hello')
channel.[1]()
Drag options to blanks, or click blank then click option'
Await_for_confirmation
Bwait_for_ack
Cwait_for_confirms
Dwait_for_confirm
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'wait_for_ack'.
Not waiting for confirms after publishing.
3fill in blank
hard

Fix the error in the code to properly handle publisher confirms.

RabbitMQ
channel.basic_publish(exchange='', routing_key='jobs', body='Run')
if not channel.[1]():
    print('Message not confirmed!')
Drag options to blanks, or click blank then click option'
Await_for_confirms
Bwait_for_confirm
Cwait_for_ack
Dwait_for_confirmation
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist or returns nothing.
Assuming the publish method itself returns confirmation.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps message IDs to their confirmation status.

RabbitMQ
confirms = {msg_id: channel.[1](msg_id) for msg_id in message_ids if channel.[2](msg_id)}
Drag options to blanks, or click blank then click option'
Ais_confirmed
Bis_pending
Cis_acknowledged
Dis_rejected
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the methods or using non-existent ones.
Using the same method for both blanks.
5fill in blank
hard

Fill all three blanks to create a dictionary of message IDs and their statuses filtered by confirmed messages.

RabbitMQ
confirmed_msgs = {msg_id: status for msg_id, status in statuses.items() if msg_id [1] confirmed_ids and status [2] 'ack' and not status [3] 'nack'}
Drag options to blanks, or click blank then click option'
Ain
B==
C!=
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' instead of 'in' for membership check.
Confusing equality and inequality operators.

Practice

(1/5)
1. What does enabling publisher confirms in RabbitMQ do?
easy
A. It automatically retries sending messages on failure.
B. It encrypts messages before sending.
C. It tells you if RabbitMQ accepted your message.
D. It queues messages without sending them.

Solution

  1. Step 1: Understand the purpose of publisher confirms

    Publisher confirms notify the sender if the message was accepted by RabbitMQ.
  2. Step 2: Compare with other options

    Retrying, encrypting, or queuing without sending are unrelated to confirms.
  3. Final Answer:

    It tells you if RabbitMQ accepted your message. -> Option C
  4. Quick Check:

    Publisher confirms = message acceptance notification [OK]
Hint: Publisher confirms confirm message acceptance by RabbitMQ [OK]
Common Mistakes:
  • Confusing confirms with message encryption
  • Thinking confirms retry messages automatically
  • Assuming confirms delay message sending
2. Which method must be called on a RabbitMQ channel to enable publisher confirms?
easy
A. enableConfirms()
B. setConfirmMode()
C. startConfirm()
D. confirmSelect()

Solution

  1. Step 1: Recall the correct method name

    The method to enable confirms on a channel is confirmSelect().
  2. Step 2: Verify other options

    Other method names like enableConfirms() or startConfirm() do not exist in RabbitMQ API.
  3. Final Answer:

    confirmSelect() -> Option D
  4. Quick Check:

    Enable confirms = confirmSelect() [OK]
Hint: Enable confirms by calling confirmSelect() on the channel [OK]
Common Mistakes:
  • Using incorrect method names like enableConfirms()
  • Forgetting to call confirmSelect() before publishing
  • Confusing confirmSelect() with waitForConfirms()
3. Given this code snippet, what will waitForConfirms() return if the message was accepted?
channel.confirmSelect();
channel.basicPublish(exchange, routingKey, props, body);
boolean confirmed = channel.waitForConfirms();
System.out.println(confirmed);
medium
A. false
B. true
C. null
D. Exception thrown

Solution

  1. Step 1: Understand waitForConfirms() behavior

    This method returns true if RabbitMQ accepted the message, false otherwise.
  2. Step 2: Given the message was accepted

    The variable confirmed will be true, so printing it outputs 'true'.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    Message accepted = waitForConfirms() returns true [OK]
Hint: waitForConfirms() returns true if message accepted [OK]
Common Mistakes:
  • Expecting waitForConfirms() to return false on success
  • Assuming it returns null or throws exception on success
  • Confusing waitForConfirms() with asynchronous callbacks
4. What is wrong with this code snippet for enabling publisher confirms?
channel.basicPublish(exchange, routingKey, props, body);
channel.confirmSelect();
boolean confirmed = channel.waitForConfirms();
medium
A. confirmSelect() must be called before basicPublish()
B. waitForConfirms() cannot be called after publishing
C. basicPublish() requires a callback parameter
D. confirmSelect() should be called after waitForConfirms()

Solution

  1. Step 1: Check order of method calls

    confirmSelect() must be called before publishing to enable confirms.
  2. Step 2: Identify the error

    In the snippet, confirmSelect() is called after basicPublish(), so confirms are not enabled when publishing.
  3. Final Answer:

    confirmSelect() must be called before basicPublish() -> Option A
  4. Quick Check:

    Enable confirms before publishing [OK]
Hint: Call confirmSelect() before publishing messages [OK]
Common Mistakes:
  • Calling confirmSelect() after publishing
  • Thinking waitForConfirms() disables confirms
  • Believing basicPublish() needs a callback for confirms
5. You want to ensure your application only proceeds after RabbitMQ confirms message acceptance. Which sequence of calls correctly implements this using publisher confirms?
hard
A. channel.confirmSelect(); channel.basicPublish(...); channel.waitForConfirms();
B. channel.basicPublish(...); channel.waitForConfirms(); channel.confirmSelect();
C. channel.waitForConfirms(); channel.confirmSelect(); channel.basicPublish(...);
D. channel.basicPublish(...); channel.confirmSelect(); channel.waitForConfirms();

Solution

  1. Step 1: Enable confirms before publishing

    Call confirmSelect() first to enable confirms on the channel.
  2. Step 2: Publish the message and wait for confirmation

    After basicPublish(...), call waitForConfirms() to block until RabbitMQ confirms acceptance.
  3. Final Answer:

    channel.confirmSelect(); channel.basicPublish(...); channel.waitForConfirms(); -> Option A
  4. Quick Check:

    Enable confirms, publish, then wait [OK]
Hint: Enable confirms, publish, then waitForConfirms() [OK]
Common Mistakes:
  • Calling confirmSelect() after publishing
  • Waiting for confirms before publishing
  • Not calling waitForConfirms() at all
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