PHP code example of mix8872 / rabbitmq-rpc

1. Go to this page and download the library: Download mix8872/rabbitmq-rpc 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/ */

    

mix8872 / rabbitmq-rpc example snippets


...
'queues' => [
        '<имя_сервиса>' => [
            'connection' => 'grch',
            'name' => '<имя_сервиса>',
            'attributes' => [
                'durable' => true,
                'bind' => [
                    ['exchange' => 'GRCHExchanger', 'routing_key' => 'projectsData'], // подписываем очередь на обновления проектов
                    ['exchange' => 'GRCHExchanger', 'routing_key' => 'usersData'], // подписываем очередь на обновления пользователей
                    ['exchange' => 'GRCHExchanger', 'routing_key' => \config('app.name')], // собственная очередь сервиса
                ],
            ],
        ],
    ],
...

...
'consumers' => [
        '<имя_сервиса>' => [
            'queue' => '<имя_сервиса>',
            'message_processor' => RMQRpcProcessor::class,
        ],
    ],
...

...
'rpc' => [
        'processors' => [
            'users' => UsersProcessor::class,
            'projects' => ProjectsProcessor::class,
        ],
    ],
...

RMQRpcPublisher::make()
    ->action('projects.create')
    ->attributes([
        'project' => $project->toArray(),
    ])
    ->publish('projectsData');

RMQRpcPublisher::make()
    ->error(<текст_ошибки>)
    ->replyFor(<request_id_из_предыдущего_запроса>)
    ->publish(<reply_to_из_предыдущего_запроса>);