liveBook · Manning

MessageQueueTrigger

As explained in Data Pipelines with Apache Airflow, Second Edition

MessageQueueTrigger is an Airflow trigger implementation that asynchronously monitors a message queue for events matching its conditions.

When an external system finishes uploading data, it can publish a message instead of creating a completion file. MessageQueueTrigger monitors that queue and lets Airflow respond when a matching message arrives, supporting near-real-time workflow activation. section 7.3 section 7.4

Configure the trigger with a queue URI and an apply_function. The function receives each message and returns a Boolean, allowing irrelevant messages to be filtered. Attach the trigger to an Asset through AssetWatcher, then use that asset in the DAG’s schedule. section 7.3

Triggering a DAG from Kafka

from airflow.providers.common.messaging.triggers.msg_queue import MessageQueueTrigger from airflow.sdk import Asset, AssetWatcher trigger = MessageQueueTrigger( queue="kafka://kafka:9092/events", apply_function="custom.kafka_util.apply_function", ) asset = Asset("kafka_queue_asset", watchers=[ AssetWatcher(name="kafka_watcher", trigger=trigger) ]) with DAG(dag_id="12_kafka_trigger", schedule=[asset]): copy >> process >> create_metrics Produce a message with Kafka’s console producer; the DAG may start after the consumer’s configurable fetch interval.

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Explains configuration, filtering, asset wiring, Kafka execution, and consumer delay, but does not detail trigger internals.
Examples
Demonstrates supermarket uploads, Kafka topics, apply_function filtering, AssetWatcher configuration, CLI production, and ordered DAG tasks.
What it assumes
Assumes familiarity with Airflow DAGs and assets while demonstrating the queue trigger and message-filtering pattern directly.
What you can do after
Configure Airflow and Kafka to trigger a DAG from published messages and filter which messages qualify.
How it connects
Connects message queues with Airflow DAGs, assets, AssetWatcher, Kafka, FileSensor, REST API, and datasets/events.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.