<?php
namespace Illuminate\Queue\Console;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Queue\Factory;
use Illuminate\Queue\Events\QueueBusy;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'queue:monitor')]
class MonitorCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:monitor
{queues : The names of the queues to monitor}
{--max=1000 : The maximum number of jobs that can be on the queue before an event is dispatched}';
/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*
* @deprecated
*/
protected static $defaultName = 'queue:monitor';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Monitor the size of the specified queues';
/**
* The queue manager instance.
*
* @var \Illuminate\Contracts\Queue\Factory
*/
protected $manager;
/**
* The events dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* The table headers for the command.
*
* @var string[]
*/
protected $headers = ['Connection', 'Queue', 'Size', 'Status'];
/**
* Create a new queue monitor command.
*
* @param \Illuminate\Contracts\Queue\Factory $manager
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function __construct(Factory $manager, Dispatcher $events)
{
parent::__construct();
$this->manager = $manager;
$this->events = $events;
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$queues = $this->parseQueues($this->argument('queues'));
$this->displaySizes($queues);
$this->dispatchEvents($queues);
}
/**
* Parse the queues into an array of the connections and queues.
*
* @param string $queues
* @return \Illuminate\Support\Collection
*/
protected function parseQueues($queues)
{
return collect(explode(',', $queues))->map(function ($queue) {
[$connection, $queue] = array_pad(explode(':', $queue, 2), 2, null);
if (! isset($queue)) {
$queue = $connection;
$connection = $this->laravel['config']['queue.default'];
}
return [
'connection' => $connection,
'queue' => $queue,
'size' => $size = $this->manager->connection($connection)->size($queue),
'status' => $size >= $this->option('max') ? '<fg=yellow;options=bold>ALERT</>' : '<fg=green;options=bold>OK</>',
];
});
}
/**
* Display the queue sizes in the console.
*
* @param \Illuminate\Support\Collection $queues
* @return void
*/
protected function displaySizes(Collection $queues)
{
$this->newLine();
$this->components->twoColumnDetail('<fg=gray>Queue name</>', '<fg=gray>Size / Status</>');
$queues->each(function ($queue) {
$status = '['.$queue['size'].'] '.$queue['status'];
$this->components->twoColumnDetail($queue['queue'], $status);
});
$this->newLine();
}
/**
* Fire the monitoring events.
*
* @param \Illuminate\Support\Collection $queues
* @return void
*/
protected function dispatchEvents(Collection $queues)
{
foreach ($queues as $queue) {
if ($queue['status'] == '<fg=green;options=bold>OK</>') {
continue;
}
$this->events->dispatch(
new QueueBusy(
$queue['connection'],
$queue['queue'],
$queue['size'],
)
);
}
}
}
Get access token to initiates payment transaction.
generate-token
| Parameter | Type | Comments |
|---|---|---|
| client_id | string | Enter merchant API client/primary key |
| secret_id | string | Enter merchant API secret key |
| env | string | Enter merchant API environment |
| merchant_id | string | Enter merchant API merchant id |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url. 'v1/generate-token', [
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'client_id' => '$client_id',
'secret_id' => 'secret_id',
'env' => 'env',
'merchant_id' => 'merchant_id',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Successfully token is generated"
]
},
"data": {
"token":"eyJpdiI6InpkczhjTjhQdVhUL2lKQ0pSUUx6aUE9PSIsInZhbHVlIjoiVGVBTVBDTXltbjNZcEIvdEJveGpTSno3TU5NRUtnVkhCZ1pHTFNCUnZGQ2UxMnYxN202cEE1YVRDTEFsc0ZERExoTjdtL0dTL2xoU3QzeUJJOExiMUx5T0w1L0llUXhTUkU1cWVLWEdEbEplb0dKNXcwbTNRM0VxdkUwYzZuNFdtNkhMQ0pRZysyNWkvdzBxSlBoSVBSOGFTekNnR2RXNHVtcG9lMGZOTmNCcm1hR3c5Sk9KTnB4Y3ltZDl6cm90MThrR21Ca3B1azc3bXRiQ0J6SW96UVo1elNkU1ZqeE05bTcwWGp1MEUxWlJFdnNWTmpSbnVpeW92b2U4dXZkUGgyb1VmK0luaGdyaFlsVTZlcVpVRnZlTG1DeFF6Ykk2T2h6Z3JzbnIyNHpNdHowSE5JdDR0Y0pZT20zUm1XYW8iLCJtYWMiOiJlY2M4NGE1OGUzYzkzYzk0YzljNmVmNjE0YWI0ZDIwOGI3NDQ2YWEyY2ZhNzc0NzE4ZmY1ZmYyMz
IyZmQzNDY1IiwidGFnIjoiIn0=",
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid credentials."
]
},
"data": null,
"type": "error"
}