Bird
0
0

Given the following Python code snippet using pika library, what will be the output or result?

medium📝 Command Output Q13 of 15
RabbitMQ - Performance Tuning
Given the following Python code snippet using pika library, what will be the output or result?
channel.txSelect()
for i in range(3):
    channel.basic_publish(exchange='', routing_key='queue', body=f'Msg {i}')
channel.txCommit()
print('Batch sent')
AThree messages are sent together, then 'Batch sent' is printed.
BNo messages are sent because txCommit() is missing.
CAn error occurs because txSelect() is not valid in pika.
D'Batch sent' is printed but messages are sent one by one immediately.
Step-by-Step Solution
Solution:
  1. Step 1: Understand transaction usage in code

    txSelect() starts transaction, messages are published in loop, then txCommit() sends them all.
  2. Step 2: Identify output and message sending behavior

    Messages are sent together after commit, then 'Batch sent' prints.
  3. Final Answer:

    Three messages are sent together, then 'Batch sent' is printed. -> Option A
  4. Quick Check:

    txCommit() sends batch, then print [OK]
Quick Trick: txCommit() sends all messages at once after txSelect() [OK]
Common Mistakes:
MISTAKES
  • Thinking messages send immediately without commit
  • Assuming txSelect() is invalid in pika
  • Forgetting txCommit() means no send

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More RabbitMQ Quizzes