0
0
GCPcloud~10 mins

Message ordering in GCP - Interactive Code Practice

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

Complete the code to enable message ordering in a Pub/Sub topic.

GCP
topic = publisher.topic_path(project_id, [1])
publisher.create_topic(request={"name": topic, "message_ordering_enabled": true})
Drag options to blanks, or click blank then click option'
A"topic-name"
B"pubsub-topic"
C"my-topic"
D"ordered-topic"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic topic name that doesn't indicate ordering
Not enabling message ordering in topic creation
2fill in blank
medium

Complete the code to publish a message with ordering key.

GCP
future = publisher.publish(topic, data=b"Hello, world!", ordering_key=[1])
Drag options to blanks, or click blank then click option'
A"123"
B"key1"
C"order-1"
D"msg-key"
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-string types for ordering key
Leaving ordering key empty
3fill in blank
hard

Fix the error in subscriber code to enable message ordering.

GCP
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(project_id, subscription_name)
flow_control = pubsub_v1.types.FlowControl(max_messages=10)
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback, flow_control=[1], enable_message_ordering=True)
Drag options to blanks, or click blank then click option'
Amax_messages
BNone
Cflow_control
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer instead of flow control object
Passing None disables flow control and may break ordering
4fill in blank
hard

Fill both blanks to configure the subscriber to acknowledge messages in order.

GCP
def callback(message):
    print(f"Received message: {message.data.decode('utf-8')}")
    message.[1]()

subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(project_id, subscription_name)
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback, enable_message_ordering=[2])
Drag options to blanks, or click blank then click option'
Aack
Bnack
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using nack() instead of ack()
Not enabling message ordering in subscriber
5fill in blank
hard

Fill all three blanks to create a topic, publish ordered messages, and enable ordering in subscriber.

GCP
topic = publisher.topic_path(project_id, [1])
publisher.create_topic(request={"name": topic, "message_ordering_enabled": [2])

future = publisher.publish(topic, data=b"Test", ordering_key=[3])
Drag options to blanks, or click blank then click option'
A"ordered-topic"
BTrue
C"key-123"
D"normal-topic"
Attempts:
3 left
💡 Hint
Common Mistakes
Not enabling message ordering in topic creation
Using a topic name that doesn't reflect ordering
Publishing without an ordering key