Open a command console, enter your project directory and execute:
$ composer require esb/health-check-symfony
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
<?php
// config/bundles.php
return [
// ...
Esb\HealthCheckSymfony\HealthCheckSymfonyBundle::class => ['all' => true],
];
config/packages/health_check_symfony.yaml
health_check_symfony:
checks:
- id: Esb\HealthCheckSymfony\Checks\DoctrineCheck
- id: Esb\HealthCheckSymfony\Checks\RedisCheck
rabbitmq_queues: # optional
- name: 'queue_name'
kafka: # optional
group:
broker_list:
sasl_username:
sasl_password:
security_protocol:
sasl_mechanism:
env: test
topics:
- name: topic_name # env is concatenated, example: test.topic_name
config/routes/health_check_symfony.yaml
health_check:
path: /healthcheck
methods: GET
controller: Esb\HealthCheckSymfony\Controller\HealthCheckController::index
config/packages/security.yaml
If you are using symfony/security and your health check is to be used anonymously, add a new firewall to the configuration
firewalls:
healthcheck:
pattern: ^/healthcheck
security: false
It is possible to add your custom health check:
<?php
declare(strict_types=1);
namespace YourProject\Check;
use Esb\HealthCheck\HealthCheck;
use Esb\HealthCheck\Status;
class CustomCheck extends HealthCheck
{
public function name(): string
{
return 'custom_check_name';
}
public function handle(): Status
{
return $this->okay();
}
}
Then add custom health check to collection
health_check_symfony:
checks:
- id: Esb\HealthCheckSymfony\Checks\DoctrineCheck
- id: Esb\HealthCheckSymfony\Checks\RedisCheck
- id: YourProject\Check\CustomCheck