fivelab / amqp-bundle
The bundle for integrate fivelab/amqp library with Symfony application
Installs: 18 396
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- php: ^8.2
- fivelab/amqp: ~2.1.0
- symfony/dependency-injection: ~5.4 | ~6.0 | ~7.0
- symfony/framework-bundle: ~5.4 | ~6.0 | ~7.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ~3.5
- fivelab/ci-rules: dev-master
- matthiasnoback/symfony-dependency-injection-test: ~4.0
- phpmetrics/phpmetrics: ^2.0
- phpunit/phpunit: ~10.1
- symfony/console: ~5.4 | ~6.0
- symfony/expression-language: ~5.4 | ~6.0
README
#StandWithUkraineAMQP Bundle
Integrate the AMQP library with you Symfony application.
Sample configuration
fivelab_amqp: connections: default: dsn: 'amqp://guest:guest@127.0.0.1:5672/%2f?read_timeout=30&other_parameter=some' exchanges: primary: connection: default name: direct type: direct durable: true publishers: primary: exchange: primary queues: collect_reports: name: reports.collect connection: default bindings: - { exchange: primary, routing: customer.register } - { exchange: primary, routing: customer.activate } consumers: collect_reports: queue: collect_repots message_handlers: 'acme.service.collect_reports_message_handler'
Initialize
After install and configure bundle, you can initialize all exchanges and queues:
./bin/console event-broker:initialize:exchanges ./bin/console event-broker:initialize:queues
After initialize exchanges and queues you can run consumer:
./bin/console event-broker:consumer:run collect_reports
For debug, you can use verbosity levels.
Publish messages
For publish messages to broker, we use Publisher
system. You can configure more publishers.
<?php namespace Acme\Controller; use FiveLab\Component\Amqp\Publisher\PublisherInterface; use FiveLab\Component\Amqp\Message\Message; use FiveLab\Component\Amqp\Message\Payload; class MyController { public function __construct(private PublisherInterface $publisher) { $this->publisher = $publisher; } public function handleAction(): void { $payload = new Payload('hello world'); $message = new Message($payload); $this->publisher->publish($message, 'customer.register'); } }
Transactional
RabbitMQ supports transactional layer, and we implement it. For use transactional layer you must create new channel for transactional layer and use this channel in you publisher:
fivelab_amqp: # Configure connections, etc... channels: transactional: connection: default publishers: # Publishers primary_transactional: exchange: primary channel: transactional savepoint: false
Note: you should start/commit/rollback transaction directly in you application (on middleware layers on command bus as an example). See
FiveLab\Component\Amqp\Channel\ChannelInterface::(start|commit|rollback)Transaction
methods.
If you want to use savepoint, you can set true
for savepoint
. We implement this functionality
(\FiveLab\Component\Amqp\Publisher\SavepointPublisherDecorator
).
Development
For easy development you can use the Docker
.
docker build -t amqp-bundle . docker run -it \ --name amqp-bundle \ -v $(pwd):/code \ amqp-bundle bash
After success run and attach to container you must install vendors:
composer install
Before create the PR or merge into develop, please run next commands for validate code:
./bin/phpunit ./bin/phpcs --config-set show_warnings 0 ./bin/phpcs --standard=vendor/escapestudios/symfony2-coding-standard/Symfony/ src/ ./bin/phpcs --standard=tests/phpcs-ruleset.xml tests/