Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a RabbitMQ cluster node connection.
RabbitMQ
connection = pika.BlockingConnection(pika.ConnectionParameters(host=[1])) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' instead of the cluster node name.
Using IP address instead of the cluster node name.
✗ Incorrect
The host should be the cluster node name to connect to the RabbitMQ cluster.
2fill in blank
mediumComplete the code to declare a durable queue for high availability.
RabbitMQ
channel.queue_declare(queue='task_queue', durable=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting durable to False causes the queue to be deleted on restart.
Using None or 0 instead of a boolean value.
✗ Incorrect
Setting durable=True ensures the queue survives RabbitMQ restarts, supporting high availability.
3fill in blank
hardFix the error in the code to enable mirrored queues for clustering high availability.
RabbitMQ
args = {'x-ha-policy': [1]
channel.queue_declare(queue='task_queue', durable=True, arguments=args) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'none' disables mirroring.
Using 'mirror' or 'single' are invalid policies.
✗ Incorrect
The 'x-ha-policy' set to 'all' enables queue mirroring across all nodes for high availability.
4fill in blank
hardFill both blanks to set up a RabbitMQ cluster connection with automatic recovery and heartbeat.
RabbitMQ
parameters = pika.ConnectionParameters(host='cluster-node-1', heartbeat=[1], blocked_connection_timeout=[2]) connection = pika.BlockingConnection(parameters)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting heartbeat too high causes delays in detecting failures.
Setting blocked_connection_timeout too low causes premature disconnects.
✗ Incorrect
Heartbeat of 30 seconds keeps connection alive; blocked_connection_timeout of 300 seconds helps recovery.
5fill in blank
hardFill all three blanks to implement a retry mechanism for connecting to a RabbitMQ cluster.
RabbitMQ
for attempt in range([1]): try: connection = pika.BlockingConnection(pika.ConnectionParameters(host='cluster-node-1')) break except pika.exceptions.AMQPConnectionError: time.sleep([2]) else: raise Exception('Failed to connect after [3] attempts')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few retries causes early failure.
Using too long sleep delays recovery.
✗ Incorrect
Retry 5 times, wait 2 seconds between tries, and raise error after 5 attempts.