PHP code example of a-mazalov / kali-message-broker

1. Go to this page and download the library: Download a-mazalov/kali-message-broker 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/ */

    

a-mazalov / kali-message-broker example snippets


    use Kali\MessageBroker\Messages\Data\Test;
    use Kali\MessageBroker\Notifications\RabbitmqMessageNotification;

    $testData = new Test(email: "[email protected]", message: "Hello World!");
    $routing_key = "access" // очередь сервиса в который необходимо отправить сообщение. Роутинг настраивается через Exchange в админке RabbitMQ 

    Notification::route("rabbitmq", $routing_key)->notify(
        new RabbitmqMessageNotification("TestJob", $testData->toResource())
    );
 artisan rabbitmq:consume

        'rabbitmq_consumer' => [
            'driver' => 'rabbitmq',
            'queue' => env('RABBITMQ_QUEUE', 'default'),
            'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,

            'hosts' => [
                [
                    'host' => env('RABBITMQ_HOST', '127.0.0.1'),
                    'port' => env('RABBITMQ_PORT', 5672),
                    'user' => env('RABBITMQ_USER', 'guest'),
                    'password' => env('RABBITMQ_PASSWORD', 'guest'),
                    'vhost' => env('RABBITMQ_VHOST', '/'),
                ],
            ],

            'options' => [
                'ssl_options' => [
                    'cafile' => env('RABBITMQ_SSL_CAFILE', null),
                    'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
                    'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
                    'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
                    'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
                ],
                'queue' => [
                    'job' => \Kali\MessageBroker\Worker\ConsumeRabbitMQ::class,
                ],
            ],

            /*
             * Set to "horizon" if you wish to use Laravel Horizon.
             */
            'worker' => env('RABBITMQ_WORKER', 'default'),
        ],

    'queue' => [
        'job' => \Kali\MessageBroker\Worker\ConsumeRabbitMQ::class,
    ],
 artisan vendor:publish
 artisan rabbitmq:consume rabbitmq_consumer
config/queue.php
config/message.php
config/queue.php