Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
RabbitMQPing
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 handle
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Console\Commands;
4
5use Illuminate\Console\Command;
6use PhpAmqpLib\Connection\AMQPStreamConnection;
7
8class RabbitMQPing extends Command
9{
10    protected $signature   = 'rabbitmq:ping';
11    protected $description = 'Ping RabbitMQ server';
12
13    public function handle(): void
14    {
15        try {
16
17            $user = env('RABBIT_USER');
18            $pass = env('RABBIT_PASS');
19            $host = env('RABBIT_HOST');
20            $port = env('RABBIT_PORT');
21
22            $connection = new AMQPStreamConnection($host, $port, $user, $pass);
23            $connection->close();
24
25            $this->info('Successfully pinged RabbitMQ server!');
26        } catch (\Exception $e) {
27            $this->error('Failed to ping RabbitMQ server. Error: ' . $e->getMessage());
28        }
29    }
30}