A lightweight, drop-in solution for independently compressing and encrypting Symfony Messenger payloads before sending them to message brokers (like Redis, RabbitMQ, or Doctrine).
- Compression: Shrink massive payloads (e.g., bulk exports, huge data syncs) to fit within message broker limits.
- Encryption: Protect sensitive data (PII) so it's never stored in plain text in your infrastructure (Redis, RabbitMQ, DB).
- Granular Control: Use
CompressStamponly,SecureStamponly, or both together. - Transparent Consumption: The serializer automatically detects headers (
X-Compressed,X-Secured) and restores the payload before it hits your handler. - AES-256-CBC Encryption: Industry-standard security for data at rest in your queue.
- gzdeflate Compression: Highly efficient storage reduction.
- Decorator Pattern: Wraps the native Symfony Messenger serializer for full compatibility.
- PHP 8.2+
- Composer
- Symfony CLI (optional, but recommended)
- Clone the repository:
git clone https://github.com/mattleads/CompressStamp.git cd CompressStamp - Install dependencies:
composer install
Add a secure string to your .env file:
MESSENGER_ENCRYPTION_KEY="ChangeMeToASecureRandomKey123!"Decorate the default messenger serializer in your config/services.yaml:
services:
App\Messenger\Serialization\CompressSerializer:
arguments:
$innerSerializer: '@messenger.default_serializer'
$encryptionKey: '%env(MESSENGER_ENCRYPTION_KEY)%'Update config/packages/messenger.yaml:
framework:
messenger:
transports:
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: App\Messenger\Serialization\CompressSerializeruse App\Messenger\Stamp\CompressStamp;
use App\Messenger\Stamp\SecureStamp;
$bus->dispatch(new MyMessage($data), [
new CompressStamp(),
new SecureStamp()
]);$bus->dispatch(new MyMessage($data), [
new SecureStamp()
]);$bus->dispatch(new MyMessage($data), [
new CompressStamp()
]);- Install:
composer install - Consume:
php bin/console messenger:consume async -vv - Trigger:
php bin/console app:trigger-bulk-invoice
- Compression: If
CompressStampis present, the body is compressed andX-Compressed: trueis added. - Encryption: If
SecureStampis present, the (potentially compressed) body is encrypted using AES-256-CBC andX-Secured: trueis added.
- Decryption: If
X-Securedis found, the body is decrypted using your key. - Decompression: If
X-Compressedis found, the body is then decompressed. - Hydration: The resulting clean payload is passed to the inner serializer to become a PHP object. ject.