PHP code example of danikdantist / queue-wrapper

1. Go to this page and download the library: Download danikdantist/queue-wrapper 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/ */

    

danikdantist / queue-wrapper example snippets




class Receiver implements DanikDantist\QueueWrapper\Interfaces\iReceivable
{
    public function receiveMessage(DanikDantist\QueueWrapper\Message $message)
    {
        echo $message->toString()."\n";
    }
}

class EchoLogger implements DanikDantist\QueueWrapper\Interfaces\iLogable
{
    public function info($info)
    {
        echo 'Info: '.$info."\n";
    }

    public function error($error)
    {
        echo 'Error: '.$error."\n";
    }
}

$config = new DanikDantist\QueueWrapper\Drivers\Kafka\Config();
$config
    ->setGroup('my_group')
    ->addBroker('172.17.0.31:9092')
    ->addTopic('my-test-topic')
    ->addTopic('my-test-topic-2')
;

$demon = new DanikDantist\QueueWrapper\Manager(new DanikDantist\QueueWrapper\Drivers\Kafka\Connector($config, new EchoLogger()));
$demon->addReceiver(new Receiver());
$demon->listenMessage();



class EchoLogger implements DanikDantist\QueueWrapper\Interfaces\iLogable
{
    public function info($info)
    {
        echo 'Info: '.$info."\n";
    }

    public function error($error)
    {
        echo 'Error: '.$error."\n";
    }
}

$config = new DanikDantist\QueueWrapper\Drivers\Kafka\Config();
$config->addBroker('172.17.0.31:9092');

$demon = new DanikDantist\QueueWrapper\Manager(new DanikDantist\QueueWrapper\Drivers\Kafka\Connector($config, new EchoLogger()));

$demon->sendMessage(new DanikDantist\QueueWrapper\Message('My test message', 'my-test-topic'));