PHP code example of symfony-bundles / kafka-bundle
1. Go to this page and download the library: Download symfony-bundles/kafka-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symfony-bundles / kafka-bundle example snippets
namespace App\Consumer;
use Swift_Mailer;
use Mgid\KafkaBundle\Command\Consumer;
class EmailSendConsumer extends Consumer
{
public const QUEUE_NAME = 'email_send_queue';
/**
* @var Swift_Mailer
*/
private $mailer;
/**
* @(new \Swift_Message($data['subject']))
->setFrom($data['sender'])
->setTo($data['recipient'])
->setBody($data['body']);
$this->mailer->send($message);
}
}
namespace App\Service;
use App\Consumer\DemoConsumer;
use Mgid\KafkaBundle\DependencyInjection\Traits\ProducerTrait;
class EmailService
{
use ProducerTrait;
/**
* @param array $data
*/
public function send(array $data): void
{
$this->producer->send(DemoConsumer::QUEUE_NAME, $data);
}
}