Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a queue in RabbitMQ.
RabbitMQ
channel.queue_declare(queue=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the queue name.
✗ Incorrect
The queue name must be a string enclosed in quotes.
2fill in blank
mediumComplete the code to publish a message to a queue.
RabbitMQ
channel.basic_publish(exchange='', routing_key=[1], body=message)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty string or variable instead of queue name.
✗ Incorrect
The routing_key should be the queue name as a string.
3fill in blank
hardFix the error in the consumer callback function to acknowledge message receipt.
RabbitMQ
def callback(ch, method, properties, body): print(f"Received {body}") ch.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter for delivery_tag.
✗ Incorrect
The delivery_tag is accessed from the method parameter to acknowledge the message.
4fill in blank
hardFill both blanks to create a durable queue and persistent message.
RabbitMQ
channel.queue_declare(queue='task_queue', durable=[1]) channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting durable to False or missing delivery_mode=2.
✗ Incorrect
Durable queues survive server restarts and persistent messages are marked with delivery_mode=2.
5fill in blank
hardFill all three blanks to set up a fanout exchange and bind a queue to it.
RabbitMQ
channel.exchange_declare(exchange=[1], exchange_type=[2]) channel.queue_bind(exchange=[3], queue='logs')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exchange type or mismatched exchange names.
✗ Incorrect
The exchange is named 'logs_exchange' with type 'fanout'. The queue is bound to the same exchange.