0
0
RabbitMQdevops~10 mins

Direct exchange in RabbitMQ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a direct exchange named 'logs'.

RabbitMQ
channel.exchange_declare(exchange='logs', exchange_type='[1]')
Drag options to blanks, or click blank then click option'
Adirect
Btopic
Cfanout
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fanout' instead of 'direct' will broadcast messages to all queues.
Using 'topic' requires pattern matching, not exact routing keys.
2fill in blank
medium

Complete the code to bind the queue 'error_logs' to the exchange 'logs' with routing key 'error'.

RabbitMQ
channel.queue_bind(queue='error_logs', exchange='logs', routing_key='[1]')
Drag options to blanks, or click blank then click option'
Adebug
Berror
Cwarning
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using a routing key that does not match the message's routing key will prevent message delivery.
Binding to the wrong exchange name will cause errors.
3fill in blank
hard

Fix the error in the code to publish a message with routing key 'info' to the 'logs' exchange.

RabbitMQ
channel.basic_publish(exchange='logs', routing_key='[1]', body='System started')
Drag options to blanks, or click blank then click option'
Ainfo
Berror
Cwarning
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using a routing key that does not match any queue bindings results in message loss.
Misspelling the routing key causes routing failures.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps routing keys to their message counts only if the count is greater than 5.

RabbitMQ
{key: counts[1] for key in counts if counts[key][2] 5}
Drag options to blanks, or click blank then click option'
A.get(key, 0)
B<
C>
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [] instead of .get() can cause errors if key is missing.
Using '<' will filter the wrong keys.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase routing keys to their counts only if count is greater than 10.

RabbitMQ
{ [1]: [2] for [3] in counts if counts[[3]] > 10 }
Drag options to blanks, or click blank then click option'
Akey.upper()
Bcounts[key]
Ckey
Dcounts.get(key, 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using counts.get(key, 0) is safe but unnecessary if keys exist.
Using the wrong variable name in the loop causes errors.