0
0
RabbitMQdevops~10 mins

Default exchange behavior 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 publish a message to the default exchange in RabbitMQ.

RabbitMQ
channel.basic_publish(exchange=[1], routing_key='task_queue', body='Hello World!')
Drag options to blanks, or click blank then click option'
A'amq.topic'
B'default'
C'amq.direct'
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using a named exchange like 'default' instead of the empty string.
Confusing the default exchange with 'amq.direct' or 'amq.topic'.
2fill in blank
medium

Complete the code to declare a queue that will receive messages from the default exchange.

RabbitMQ
channel.queue_declare(queue=[1], durable=True)
Drag options to blanks, or click blank then click option'
A'amq.direct'
B'my_queue'
C''
D'default'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty string as queue name, which is invalid for queue declaration.
Confusing exchange names with queue names.
3fill in blank
hard

Fix the error in the code to correctly bind a queue to the default exchange.

RabbitMQ
channel.queue_bind(queue='my_queue', exchange=[1], routing_key='my_queue')
Drag options to blanks, or click blank then click option'
A''
B'amq.topic'
C'amq.direct'
D'default'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to bind a queue to the default exchange which is not allowed.
Using a named exchange instead of the empty string for the default exchange.
4fill in blank
hard

Fill both blanks to create a message consumer that listens to the queue bound to the default exchange.

RabbitMQ
channel.basic_consume(queue=[1], on_message_callback=[2], auto_ack=True)
Drag options to blanks, or click blank then click option'
A'my_queue'
Bcallback
C'default'
Dhandle_message
Attempts:
3 left
💡 Hint
Common Mistakes
Using the exchange name instead of the queue name in basic_consume.
Passing a string instead of a function as the callback.
5fill in blank
hard

Fill all three blanks to declare a queue, publish a message to the default exchange, and consume messages from the queue.

RabbitMQ
channel.queue_declare(queue=[1], durable=True)
channel.basic_publish(exchange=[2], routing_key=[3], body='Test Message')
channel.basic_consume(queue=[1], on_message_callback=process_message, auto_ack=True)
Drag options to blanks, or click blank then click option'
A'task_queue'
B''
D'amq.direct'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a named exchange instead of the empty string for the default exchange.
Mismatching queue name and routing key causing messages not to be delivered.