Complete the code to declare a queue with a dead-letter exchange for retries.
channel.queue_declare(queue='task_queue', durable=True, arguments={'x-dead-letter-exchange': '[1]'})
The dead-letter exchange is where messages are sent after they are rejected or expire. Here, 'retry_exchange' is used for retrying messages.
Complete the code to set the message TTL (time-to-live) for retry delay.
channel.queue_declare(queue='retry_queue', arguments={'x-message-ttl': [1])
The TTL is set in milliseconds. 60000 ms equals 60 seconds, a common retry delay.
Fix the error in the retry delay calculation for exponential backoff in milliseconds.
retry_delay = base_delay * (2 [1] attempt)
Exponential backoff uses power operation. The delay doubles each attempt, so base_delay * 2 ** attempt is correct.
Fill both blanks to set the dead-letter exchange and routing key for the retry queue.
channel.queue_declare(queue='retry_queue', arguments={'x-dead-letter-exchange': '[1]', 'x-dead-letter-routing-key': '[2]'})
The retry queue sends messages back to the main exchange with the routing key of the original task queue.
Fill all three blanks to create a dictionary comprehension that sets retry delays with exponential backoff for attempts 1 to 3.
retry_delays = {attempt: base_delay [1] (2 [2] attempt) for attempt in range(1, 4) if attempt [3] 3}The delay multiplies base_delay by 2 to the power of attempt. The condition includes attempts up to 3.