0
0
RabbitMQdevops~10 mins

Publish-subscribe for broadcasting 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 fanout exchange named 'logs'.

RabbitMQ
channel.exchange_declare(exchange='logs', exchange_type=[1])
Drag options to blanks, or click blank then click option'
Adirect
Bfanout
Ctopic
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'direct' instead of 'fanout' exchange type.
2fill in blank
medium

Complete the code to publish a message 'Hello World!' to the 'logs' exchange.

RabbitMQ
channel.basic_publish(exchange='logs', routing_key=[1], body='Hello World!')
Drag options to blanks, or click blank then click option'
A'info'
B'broadcast'
C'logs'
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using a routing key when publishing to a fanout exchange.
3fill in blank
hard

Fix the error in the code to bind a queue named 'task_queue' to the 'logs' exchange.

RabbitMQ
channel.queue_bind(queue='task_queue', exchange='logs', routing_key=[1])
Drag options to blanks, or click blank then click option'
A''
B'task'
C'logs'
D'broadcast'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-empty routing key when binding to a fanout exchange.
4fill in blank
hard

Fill both blanks to declare a durable queue and bind it to the 'logs' fanout exchange.

RabbitMQ
channel.queue_declare(queue=[1], durable=[2])
channel.queue_bind(queue=[1], exchange='logs', routing_key='')
Drag options to blanks, or click blank then click option'
A'task_queue'
BTrue
CFalse
D'logs_queue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different queue names in declare and bind.
Setting durable to False when persistence is needed.
5fill in blank
hard

Fill all three blanks to create a callback function that prints received messages, start consuming from 'task_queue', and acknowledge messages.

RabbitMQ
def callback(ch, method, properties, body):
    print([1])
    ch.basic_ack(delivery_tag=[2])

channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[3])
channel.start_consuming()
Drag options to blanks, or click blank then click option'
Abody.decode()
Bmethod.delivery_tag
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to decode the message body.
Using auto_ack=True which disables manual ack.