tests.system.google.event_scheduling.example_event_schedule_pubsub¶
Example Airflow DAG that demonstrates using Google Cloud Pub/Sub with MessageQueueTrigger and Asset Watchers for event-driven workflows.
This example shows how to create a DAG that triggers when messages arrive in a Google Cloud Pub/Sub subscription using Asset Watchers.
Prerequisites¶
Before running this example, ensure you have:
A GCP project with Pub/Sub API enabled
The following Pub/Sub resources created in your project:
Topic:
test-topicSubscription:
test-subscription
You can create these resources using:
# Create topic
gcloud pubsub topics create test-topic --project={PROJECT_ID}
# Create subscription
gcloud pubsub subscriptions create test-subscription \
--topic=test-topic --project={PROJECT_ID}
How to test¶
Ensure the Pub/Sub resources exist (see Prerequisites above)
Publish a message to trigger the DAG:
gcloud pubsub topics publish test-topic \ --message="Test message" --project={PROJECT_ID}
The DAG will be triggered automatically when the message arrives