Bird
0
0

You want to process messages from a Pub/Sub topic with a Cloud Function but only for messages containing the attribute "type" set to "update". How can you achieve this?

hard📝 Application Q8 of 15
GCP - Cloud Pub/Sub

You want to process messages from a Pub/Sub topic with a Cloud Function but only for messages containing the attribute "type" set to "update". How can you achieve this?

AAdd an if statement inside the function to ignore messages without "type" = "update".
BConfigure a subscription with a filter on attribute "type" = "update" and trigger the function on that subscription.
CDeploy the function with a trigger that only listens to messages with attribute "type" = "update".
DUse Cloud Scheduler to filter messages before sending to the function.
Step-by-Step Solution
Solution:
  1. Step 1: Use Pub/Sub subscription filters

    Pub/Sub supports filtering messages by attributes on subscriptions, so only matching messages are delivered.
  2. Step 2: Trigger function on filtered subscription

    Deploy the Cloud Function triggered by the filtered subscription to process only desired messages.
  3. Final Answer:

    Use a filtered subscription with attribute filter and trigger function on it. -> Option B
  4. Quick Check:

    Filter messages via subscription filters [OK]
Quick Trick: Use subscription filters to process only specific messages [OK]
Common Mistakes:
  • Filtering inside function wastes resources
  • Assuming function trigger can filter attributes
  • Using Cloud Scheduler incorrectly for filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes