PHP code example of dkhorev / laravel-ampq

1. Go to this page and download the library: Download dkhorev/laravel-ampq 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/ */

    

dkhorev / laravel-ampq example snippets


use dkhorev\LaravelAmpq\Contracts\AmpqListenCallbackContract;
use PhpAmqpLib\Message\AMQPMessage;

class MyTopicCallback implements AmpqListenCallbackContract
{
    public function __invoke(AMQPMessage $msg): void
    {
        // TODO: Implement __invoke() method.
    }
}

use dkhorev\LaravelAmpq\Clients\AmpqClient;
use dkhorev\LaravelAmpq\Contracts\SendToTopicServiceContract;

$config = config('laravel-ampq.servers.local');

$client =  new AmpqClient($config['host'], $config['user'], $config['password'], (int)$config['port']);
$sender = resolve(SendToTopicServiceContract::class);
$sender->postTo($client, 'some-exchange', 'some-topic', ['exapmple-data' => 'hello world!']);

use dkhorev\LaravelAmpq\Clients\AmpqClient;

class AmpqClientCustom extends AmpqClient implements AmpqClientCustomInterface
{}

$this->app->bind(
    AmpqClientCustomInterface::class,
    static function () {
        $config = config('laravel-ampq.servers.custom');

        return new AmpqClientCustom($config['host'], $config['user'], $config['password'], $config['port']);
    }
);

use dkhorev\LaravelAmpq\Contracts\SendToTopicServiceContract;

$sender = resolve(SendToTopicServiceContract::class);
$client = resolve(AmpqClientCustomInterface::class);

$sender->postTo($client, 'some-exchange', 'some-topic', ['exapmple-data' => 'hello world!']);