Google
Google »

PubSubPullOperator

View on GitHub

Created by

Airflow Community

Last Updated

Version

17.1.0

Pulls messages from a PubSub subscription and passes them through XCom.

Parameters

project_id

strREQUIRED

the Google Cloud project ID for the subscription (templated)

subscription

strREQUIRED

the Pub/Sub subscription name. Do not include the full subscription path.

max_messages

int

The maximum number of messages to retrieve per PubSub pull request

ack_messages

bool

If True, each message will be acknowledged immediately rather than by any downstream tasks

messages_callback

Callable[[list[ReceivedMessage], Context], Any] | None

(Optional) Callback to process received messages. Its return value will be saved to XCom. If you are pulling large messages, you probably want to provide a custom callback. If not provided, the default implementation will convert ReceivedMessage objects into JSON-serializable dicts using google.protobuf.json_format.MessageToDict function.

gcp_conn_id

str

The connection ID to use connecting to Google Cloud.

impersonation_chain

str | Sequence[str] | None

Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

deferrable

bool

If True, run the task in the deferrable mode.

poll_interval

int

Time (seconds) to wait between two consecutive calls to check the job. The default is 300 seconds.

Documentation

Pulls messages from a PubSub subscription and passes them through XCom.

If the queue is empty, returns empty list - never waits for messages. If you do need to wait, please use airflow.providers.google.cloud.sensors.PubSubPullSensor instead.

See also

For more information on how to use this operator and the PubSubPullSensor, take a look at the guide: Pulling messages from a PubSub subscription

This operator will pull up to max_messages messages from the specified PubSub subscription. When the subscription returns messages, the messages will be returned immediately from the operator and passed through XCom for downstream tasks.

If ack_messages is set to True, messages will be immediately acknowledged before being returned, otherwise, downstream tasks will be responsible for acknowledging them.

project_id `` and ``subscription are templated so you can use Jinja templating in their values.