Sobes.tech
Junior — Middle

What is your experience with message exchange systems (message broker)?

sobes.tech AI

Answer from AI

I have experience working with messaging systems such as RabbitMQ and Apache Kafka in PHP projects.

Main usage scenarios:

  • Asynchronous task processing: for example, sending emails or processing images in the background.
  • Distributed systems where components exchange events through a broker.

An example using PHP and RabbitMQ (via the php-amqplib library):

<?php
require_once __DIR__ . '/vendor/autoload.php';

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

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('task_queue', false, true, false, false);

$data = "Hello World!";
$msg = new AMQPMessage($data, ['delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]);

$channel->basic_publish($msg, '', 'task_queue');

echo " [x] Sent 'Hello World!'\n";

$channel->close();
$connection->close();

Thus, a message broker helps separate task generation from their processing, increase fault tolerance, and scalability of applications.