Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a queue named 'task_queue'.
RabbitMQ
channel.queue_declare(queue=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the queue name.
Using the wrong queue name.
✗ Incorrect
The queue name must be a string, so it needs to be enclosed in quotes.
2fill in blank
mediumComplete the code to publish a message 'Hello World!' to the default exchange with routing key 'task_queue'.
RabbitMQ
channel.basic_publish(exchange=[1], routing_key='task_queue', body='Hello World!')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' as exchange name instead of empty string.
Using None or queue name as exchange.
✗ Incorrect
The default exchange is an empty string ''.
3fill in blank
hardFix the error in the code to publish a persistent message to 'task_queue'.
RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body='Hello World!', properties=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using delivery_mode=1 which is non-persistent.
Passing delivery_mode as a string instead of integer.
Using persistent=True which is not a valid property.
✗ Incorrect
To make a message persistent, set delivery_mode=2 as an integer in BasicProperties.
4fill in blank
hardFill both blanks to publish a message with content type 'text/plain' and priority 5.
RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body='Hello', properties=pika.BasicProperties(content_type=[1], priority=[2]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong content type like 'application/json'.
Using priority as a string instead of integer.
✗ Incorrect
Content type should be 'text/plain' as a string, and priority is an integer 5.
5fill in blank
hardFill all three blanks to publish a message with delivery_mode 2, content_type 'application/json', and priority 8.
RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body='{}', properties=pika.BasicProperties(delivery_mode=[1], content_type=[2], priority=[3]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using delivery_mode 1 which is non-persistent.
Using wrong content_type string.
Using priority as string instead of integer.
✗ Incorrect
delivery_mode=2 makes message persistent, content_type is 'application/json', and priority is 8.