0
0
RabbitMQdevops~10 mins

Saga pattern for distributed transactions 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 send a message to start a saga transaction.

RabbitMQ
channel.basic_publish(exchange='saga_exchange', routing_key='start', body=[1])
Drag options to blanks, or click blank then click option'
Astart_saga()
Border_id
C'{"order_id": 123}'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a variable name instead of a JSON string
Using None as message body
2fill in blank
medium

Complete the code to acknowledge a message after processing in the saga.

RabbitMQ
channel.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
Bbody
Cchannel
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the message body instead of delivery tag
Using channel object as delivery tag
3fill in blank
hard

Fix the error in the saga compensation step to publish a rollback message.

RabbitMQ
channel.basic_publish(exchange='saga_exchange', routing_key=[1], body=rollback_data)
Drag options to blanks, or click blank then click option'
Arollback_data
Brollback
C'commit'
D'rollback'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable rollback_data as routing key
Omitting quotes around routing key
4fill in blank
hard

Fill both blanks to declare a durable queue and bind it to the saga exchange.

RabbitMQ
channel.queue_declare(queue=[1], durable=[2])
channel.queue_bind(queue='saga_queue', exchange='saga_exchange', routing_key='start')
Drag options to blanks, or click blank then click option'
A'saga_queue'
BTrue
CFalse
D'start_queue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect queue name
Setting durable to False causing message loss
5fill in blank
hard

Fill all three blanks to create a saga step that consumes messages, processes them, and sends a compensation if needed.

RabbitMQ
def on_message(channel, method, properties, body):
    data = json.loads(body)
    if data.get('status') == [1]:
        process(data)
    else:
        channel.basic_publish(exchange='saga_exchange', routing_key=[2], body=json.dumps(data))
    channel.basic_ack(delivery_tag=[3])
Drag options to blanks, or click blank then click option'
A'success'
B'rollback'
Cmethod.delivery_tag
D'fail'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status string
Not acknowledging messages properly
Using incorrect routing key for compensation