ecommit / messenger-supervisor-bundle
Use symfony/messenger with Supervisor
Installs: 1 733
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- egulias/email-validator: ^3.0|^4.0
- lstrojny/fxmlrpc: ^0.22
- nyholm/psr7: ^1.0
- psr/http-client: ^1.0
- psr/log: ^1.1|^2|^3
- supervisorphp/supervisor: ^4.0|^5.0
- symfony/config: ^5.4|^6.4|^7.0
- symfony/console: ^5.4|^6.4|^7.0
- symfony/dependency-injection: ^5.4|^6.4|^7.0
- symfony/framework-bundle: ^5.4|^6.4|^7.0
- symfony/http-client: ^5.4|^6.4|^7.0
- symfony/http-kernel: ^5.4|^6.4|^7.0
- symfony/mailer: ^5.4|^6.4|^7.0
- symfony/messenger: ^5.4|^6.4|^7.0
- symfony/twig-bridge: ^5.4|^6.4|^7.0
- symfony/twig-bundle: ^5.4|^6.4|^7.0
- twig/twig: ^2.12.0|^3.0
Requires (Dev)
- dg/bypass-finals: ^1.3
- doctrine/dbal: ^2.11.0|^3.0
- doctrine/doctrine-bundle: ^2.4.5
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10
- symfony/doctrine-messenger: ^5.4|^6.4|^7.0
- symfony/yaml: ^5.4|^6.4|^7.0
- vimeo/psalm: ^5
README
The EcommitMessengerSupervisorBundle bundle (for Symfony) manages Messenger component with Supervisor.
Available features :
- Start Supervisor programs (workers)
- Stop Supervisor programs (workers)
- Show Supervisor programs (workers) status
- Show Supervisor programs (workers) status with Nagios format
- After worker failure :
- Stop Supervisor program (can be disabled)
- Send email (can be disabled)
Installation
Install the bundle with Composer : In your project directory, execute the following command :
$ composer require ecommit/messenger-supervisor-bundle
Enable the bundle in the config/bundles.php
file for your project :
return [ //... Ecommit\MessengerSupervisorBundle\EcommitMessengerSupervisorBundle::class => ['all' => true], //... ];
In Supervisor configuration enable the API and add your workers (See the Supervisor doc for more details):
;eg in /etc/supervisor/conf.d/myconf.conf [inet_http_server] port = 127.0.0.1:9001 username = user password = 123 [program:program_async] command=php /path/to/your/app/bin/console messenger:consume async process_name=%(program_name)s_%(process_num)02d numprocs=1 autostart=true autorestart=true user=ubuntu ;You can define others programs (workers) : ;[program:program_async2] ;command=php /path/to/your/app/bin/console messenger:consume async2 ;process_name=%(program_name)s_%(process_num)02d ;numprocs=2 ;autostart=true ;autorestart=true ;user=ubuntu
Configure Messenger (See the doc for more details) and Mailer (See the doc for more details).
In your project, add the configuration file config/packages/ecommit_messenger_supervisor.yaml
:
ecommit_messenger_supervisor: supervisor: #Supervisor API configuration host: '127.0.0.1' #IP address - Required username: user #Username - Not required - Default value: null password: 123 #Password - Not required - Default value: null #port: 9001 #Port - Not required - Default value: 9001 #timeout: 3600 #API timeout (in seconds) - Not required - Default value: 3600 #Transports / Programs configuration : #Mapping "Messenger transport name" -> "Supervisor program name (group name)" transports: async: program_async #async = Messenger transport name | program_async = Supervisor program (group) name #Or you can set options : #async: # failure: # stop_program: true #Stop program after failure - Not required - Available values: "always", "will-not-retry" (only if the message cannot be retried), "never" - Default value : "always" # send_mail: true #Send mail after failure - Not required - Available values: "always", "will-not-retry" (only if the message cannot be retried), "never" - Default value : "always" #You can define others programs : #async2: program_async2 #Mailer configuration mailer: from: from@domain.com #Sender - Required if a program is setting with send_mail=true option to: to@domain.com #Recipient - Required if a program is setting with send_mail=true option #You can use multiple recipients: #to: ['to1@domain.com', 'to2@domain.com'] #subject: "[Supervisor][<server>][<program>] Error" #Suject - Not required - Default value : "[Supervisor][<program>] Error" #<program> is replaced by Supervisor program (group) name #<server> is replaced by server name
Usage
#Start a program php bin/console ecommit:supervisor start program_async #Start multiple programs php bin/console ecommit:supervisor start program_async program_async2 #Start all programs php bin/console ecommit:supervisor start all #Stop a program php bin/console ecommit:supervisor stop program_async #Stop many programs php bin/console ecommit:supervisor stop program_async program_async2 #Stop all programs php bin/console ecommit:supervisor stop all #Get status on a single program php bin/console ecommit:supervisor status program_async #Get status on multiple programs php bin/console ecommit:supervisor status program_async program_async2 #Get status on all programs php bin/console ecommit:supervisor status all #Use can use Nagios format php bin/console ecommit:supervisor status all --nagios
You can also use the Ecommit\MessengerSupervisorBundle\Supervisor\Supervisor
service :
use Ecommit\MessengerSupervisorBundle\Supervisor\Supervisor; class MyClass { protected $supervisor; public function __construct(Supervisor $supervisor) //Supervisor service is injected { $this->supervisor = $supervisor; } public function myMethod(): void { //$this->supervisor->startProgram('program_async'); //$this->supervisor->stopProgram('program_async'); //$status = $this->supervisor->getProgramsStatus(['program_async']); } }
License
This bundle is available under the MIT license. See the complete license in the LICENSE file.