0
0
GCPcloud~10 mins

Message retention and acknowledgment 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 set the acknowledgment deadline for a Pub/Sub subscription.

GCP
subscription = pubsub_client.subscription('projects/my-project/subscriptions/my-subscription')
subscription.modify_ack_deadline(seconds=[1])
Drag options to blanks, or click blank then click option'
A10
B0
C60
D300
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the deadline to 0 causes immediate redelivery.
Using a very high value delays message redelivery unnecessarily.
2fill in blank
medium

Complete the code to acknowledge a received message in Pub/Sub.

GCP
def callback(message):
    print(f'Received message: {message.data}')
    message.[1]()
Drag options to blanks, or click blank then click option'
Areject
Back
Cdelete
Dcancel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reject' instead of 'ack' does not acknowledge the message.
Calling 'delete' is not a valid method on the message object.
3fill in blank
hard

Fix the error in the code to extend the acknowledgment deadline for a message.

GCP
def callback(message):
    # Extend ack deadline by 30 seconds
    message.modify_ack_deadline(seconds=[1])
    message.ack()
Drag options to blanks, or click blank then click option'
A30
B300
C60
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 causes the message to be redelivered immediately.
Using too large a value may delay redelivery unnecessarily.
4fill in blank
hard

Fill both blanks to create a subscription with a message retention duration and enable message ordering.

GCP
subscription = pubsub_client.create_subscription(
    name='projects/my-project/subscriptions/my-subscription',
    topic='projects/my-project/topics/my-topic',
    message_retention_duration=[1],
    enable_message_ordering=[2]
)
Drag options to blanks, or click blank then click option'
A'604800s'
B'3600s'
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer instead of string for retention duration.
Setting enable_message_ordering to False disables ordering.
5fill in blank
hard

Fill all three blanks to create a pull subscription with a custom acknowledgment deadline and enable exactly-once delivery.

GCP
subscription = pubsub_client.create_subscription(
    name='projects/my-project/subscriptions/my-subscription',
    topic='projects/my-project/topics/my-topic',
    ack_deadline_seconds=[1],
    enable_exactly_once_delivery=[2],
    retain_acked_messages=[3]
)
Drag options to blanks, or click blank then click option'
A20
BTrue
CFalse
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ack_deadline_seconds too high or zero.
Disabling exactly-once delivery by setting it to False.