Amazon SQS Operators

Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.

Prerequisite Tasks

To use these operators, you must do a few things:

Amazon SQS Publish Operator

To publish a message to an Amazon SQS queue use the SqsPublishOperator

In the following example, the task "publish_to_queue" publishes a message containing the task instance and the execution date to a queue with a default name of Airflow-Example-Queue.

airflow/providers/amazon/aws/example_dags/example_sqs.py[source]

    publish_to_queue = SqsPublishOperator(
        task_id='publish_to_queue',
        sqs_queue=create_queue,
        message_content="{{ task_instance }}-{{ execution_date }}",
    )

Amazon SQS Sensor

To read messages from an Amazon SQS queue until exhausted use the SqsPublishOperator

airflow/providers/amazon/aws/example_dags/example_sqs.py[source]

    read_from_queue = SqsSensor(
        task_id='read_from_queue',
        sqs_queue=create_queue,
    )

References

For further information, look at:

Was this entry helpful?