Skip to content

SQS Sample Application

Build a consumer app that polls an SQS queue and writes every message to a file. You use Winter Boot for the application runtime and the Winter SQS module from Winter Modules for queue access. You test the whole flow locally with ElasticMQ, an SQS-compatible emulator.

You need PHP 8.5 or later with the swoole and pcntl extensions. You also need Docker to run ElasticMQ and the AWS CLI to create the queue and send messages.

Start ElasticMQ before you run the app:

Terminal window
docker run -d -p 30932:9324 softwaremill/elasticmq-native

The sample uses this layout:

sqs/
├── bin/
│ └── application.php # Application entry point
├── config/
│ ├── application.yml # Winter Boot application config
│ └── sqs-config.yml # SQS connections and consumers config
├── src/
│ ├── SqsSampleApplication.php # Main application class
│ └── consumer/
│ └── MessageFileWriterConsumer.php # SQS consumer worker
└── composer.json # Dependencies

Require the framework and the modules package:

Terminal window
composer require suvera/winter-boot suvera/winter-modules

Switch between the four source files. Each tab shows the exact file from the sample.

The single entry point. It points Winter Boot at the config directory and at the sample namespace.

<?php
namespace dev\example;
use dev\winterframework\stereotype\WinterBootApplication;
#[WinterBootApplication(
configDirectory: [__DIR__ . "/../config"],
scanNamespaces: [
['dev\\example', __DIR__ . '']
]
)]
class SqsSampleApplication {
public static function main(): void {
$winterApp = new \dev\winterframework\core\app\WinterWebSwooleApplication();
$winterApp->run(self::class);
}
}

Switch between the two config files. application.yml enables the module, and sqs-config.yml defines the connection and consumer.

The full sample file registers SqsModule and sets the server and app identity:

server:
port: 8080
address: 0.0.0.0
context-path: /
winter:
application:
name: SQS Sample Application
id: sqs-sample-app
version: 1.0.0
modules:
- module: dev\winterframework\sqs\SqsModule
enabled: true
configFile: sqs-config.yml

See Configuration for every application.yml key.

Create the queue, start the app, send a message, then check the output file.

1. Create the queue:

Terminal window
aws sqs create-queue --queue-name my-queue \
--endpoint-url http://localhost:30932 \
--region elasticmq

2. Start the application:

Terminal window
composer install
php bin/application.php

The SQS worker starts polling my-queue as soon as the app boots.

3. Send a message:

Terminal window
aws sqs send-message --queue-url http://localhost:30932/queue/my-queue \
--message-body "Hello ElasticMQ" \
--endpoint-url http://localhost:30932 \
--region elasticmq

4. Verify consumption:

Terminal window
cat /tmp/sqs-messages.txt

You see one line per consumed message, for example:

[2026-09-10 12:00:01] MessageId: abc-123 | Queue: my-queue | Body: Hello ElasticMQ
  • Read the SQS module for producer APIs (SqsService), IAM-role setup, and consumer tuning (waitTimeSeconds, maxNumberOfMessages, visibilityTimeout).
  • Browse all Libraries when you need Kafka, S3, Redis, or Doctrine in the same app.