Download the PHP package urfysoft/transactional-outbox without Composer
On this page you can find all versions of the php package urfysoft/transactional-outbox. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download urfysoft/transactional-outbox
More information about urfysoft/transactional-outbox
Files in urfysoft/transactional-outbox
Package transactional-outbox
Short Description Implements the Transactional Outbox pattern for Laravel, ensuring reliable event publishing by storing messages in an outbox table within the same database transaction.
License MIT
Homepage https://github.com/urfysoft/transactional-outbox
Informations about the package transactional-outbox
Transactional Outbox Pattern for Laravel Microservices
Complete Transactional Outbox implementation for reliable communication between microservices.
Installation
Publish assets
This command copies:
config/transactional-outbox.phpdatabase/migrations/*create_outbox_messages_table.phpdatabase/migrations/*create_inbox_messages_table.php
Run the migrations after publishing:
Configuration
Key settings live in config/transactional-outbox.php.
- Service identity & Sanctum ability
service_name: name announced in outbound headers.sanctum.required_ability: ability that incoming Sanctum tokens must possess.
- Headers
- Override header names or the prefix (default
X-) via theheadersarray.
- Override header names or the prefix (default
- Destinations
- Map logical service names to endpoints inside the
servicesarray.
- Map logical service names to endpoints inside the
- Driver
- Choose the message broker driver (
http,kafka,rabbitmqwhen implemented).
- Choose the message broker driver (
- Processing
- Control batch size, retry limits, and throttling.
- Inbox handlers
- Register classes implementing
Urfysoft\TransactionalOutbox\Contracts\InboxEventHandlerunderinbox.handlers.
- Register classes implementing
Example handler:
Register the class in config/transactional-outbox.php or at runtime:
Sanctum setup
The package expects Laravel Sanctum to be installed and configured.
Issue tokens for upstream services with the configured ability (default transactional-outbox):
Architecture Overview
Outbox Pattern (Sending Messages)
- Business logic and an outbox message are persisted in the same database transaction
- A background worker reads the outbox table and publishes to the message broker
- Messages are marked as published once delivery succeeds
- Failed messages are automatically retried
Inbox Pattern (Receiving Messages)
- Messages arrive via HTTP webhooks or a broker consumer
- Each message is stored in the inbox table for idempotency (duplicate detection)
- A background worker processes inbox messages
- Business logic runs in a transaction that also updates the message status
Usage Examples
Sending Messages to Other Services
Single destination
Multiple destinations
Receiving Messages from Other Services
Event handler registration
Inside MessageBrokerServiceProvider:
Webhook endpoint
Other services POST to:
Message Broker Options
HTTP (Default)
- Simple REST API calls
- No additional infrastructure required
- Great for small/medium deployments
Kafka
Set MESSAGE_BROKER_DRIVER=kafka
RabbitMQ
Set MESSAGE_BROKER_DRIVER=rabbitmq
Running the System
Start the scheduler (required)
Manual processing
Configuration Tips
- Header names: customize
transactional-outbox.headersto redefine which headers carry the message id, source service, event type, or to change the prefix used when collecting custom metadata. - Inbox handlers: list handler classes inside
transactional-outbox.inbox.handlers. Each class must implementUrfysoft\TransactionalOutbox\Contracts\InboxEventHandler(defineeventType()andhandle()). - Runtime registration: handlers can also be registered anywhere via the facade:
Monitoring
Key Capabilities
✅ Atomicity: Business logic and messages live in the same transaction\ ✅ Reliability: No data loss even when the broker is down\ ✅ Idempotency: Duplicate messages are automatically detected\ ✅ Retry logic: Failed deliveries are retried automatically\ ✅ Multi-broker: HTTP, Kafka, RabbitMQ drivers\ ✅ Monitoring: Track message statuses and errors\ ✅ Scalability: Batch processing support
Best Practices
- Always propagate a correlation ID for request tracing
- Keep payloads small—send references instead of full objects
- Monitor failed messages and set up alerts
- Clean up regularly to remove processed records
- Test idempotency to ensure handlers tolerate duplicates
- Use a dead-letter queue after exhausting retries
- Version your events—include a version in
event_type
Troubleshooting
Messages are not processed:
- Ensure the scheduler is running:
php artisan schedule:work - Inspect message statuses in the database
- Check logs:
tail -f storage/logs/laravel.log
Duplicate messages:
- The Inbox pattern handles duplicates automatically
- Verify
message_iduniqueness
Failed messages:
- Inspect the
last_errorcolumn - Use the retry command:
php artisan outbox:process --retry - Confirm the destination service is reachable
Advanced Topic: Saga Pattern
Combine Transactional Outbox with the Saga pattern for distributed transactions:
All versions of transactional-outbox with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0
laravel/sanctum Version ^4.2