/
ildar8919
/
Mediahosting
Обзор
Документация
Войти
/
ildar8919
/
Mediahosting
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
app/Services/RabbitMQService.php
30 строк
815 B
Ildar
Добавление новых файлов
18 янв 2025, 15:18
18 янв 2025, 15:18
a5e5342
Код
Авторство
О чём код?
<?php namespace App\Services; use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Message\AMQPMessage; class RabbitMQService { protected $connection; protected $channel; public function __construct() { $this->connection = new AMQPStreamConnection('host', 5672, 'user', 'password'); $this->channel = $this->connection->channel(); $this->channel->queue_declare('ms.pictures.updated', false, true, false, false); } public function sendMessage($data) { $msg = new AMQPMessage($data, ['delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]); $this->channel->basic_publish($msg, 'media.service', 'ms.pictures'); } public function __destruct() { $this->channel->close(); $this->connection->close(); } }