Complete the code to start a transaction in RabbitMQ channel.
channel.[1]()The tx_select() method starts a transaction mode on the channel.
Complete the code to enable publisher confirms on the channel.
channel.[1]()The confirm_select() method enables publisher confirms mode on the channel.
Fix the error in the code to commit a transaction.
channel.[1]()The tx_commit() method commits the current transaction.
Fill both blanks to publish a message and wait for confirms.
channel.basic_publish(exchange='', routing_key='task_queue', body='Hello') channel.[1]() channel.[2]()
After publishing, wait_for_confirms() waits for confirms, and tx_select() starts a transaction if used. However, typically for confirms, you enable confirms with confirm_select() before publishing and then call wait_for_confirms() after publishing.
Fill all three blanks to create a dictionary comprehension filtering messages with length greater than 5 and publishing them with confirms.
messages = {'msg1': 'Hello', 'msg2': 'Welcome', 'msg3': 'Hi there'}
filtered = {k: v for k, v in messages.items() if len(v) [1] 5}
channel.[2]()
for key, msg in filtered.items():
channel.basic_publish(exchange='', routing_key='queue', body=msg)
channel.[3]()The comprehension filters messages with length greater than 5 using '>'. Then confirm_select() enables confirms, and wait_for_confirms() waits for them after publishing.