PHP Classes

File: example/src/Workers/AlimentarQueue.php

Recommend this page to a friend!
  Classes of Matheusz Maydana   Docker Compose Auto Scaling Service   example/src/Workers/AlimentarQueue.php   Download  
File: example/src/Workers/AlimentarQueue.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Docker Compose Auto Scaling Service
Manage the deployment of services using Docker
Author: By
Last change:
Date: 1 month ago
Size: 937 bytes
 

Contents

Class file image Download
#!/usr/bin/php
<?php

declare(strict_types=1);

namespace
App\Workers;

$pathVendor = __DIR__ . '/../../vendor/autoload.php';
if(!
is_file($pathVendor)) {
    echo
"O arquivo {$pathVendor} não foi encontrado. Execute o comando composer install para instalar as dependências.";
    exit;
}

require_once
$pathVendor;

use
Exception;
use
PhpAmqpLib\Message\AMQPMessage;
use
PhpAmqpLib\Connection\AMQPStreamConnection;



$host = 'localhost';
$port = 5672;
$user = 'guest';
$pass = 'guest';
$vhost = '/';

$connection = new AMQPStreamConnection($host, $port, $user, $pass, $vhost);
$channel = $connection->channel();

// Nome da fila
$queueName = 'lancar_foguete';


$quantidadeMensagens = $argv[1] ?? 1;
for(
$i = 1; $i <= $quantidadeMensagens; $i++) {
   
$channel->basic_publish(new AMQPMessage(
       
"Foguete {$i}",
        [
           
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
        ]
    ),
'', $queueName);
}