PHP code example of serrvius / amqp-rpc-extender

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

    

serrvius / amqp-rpc-extender example snippets




namespace App\UsersModule\Query;


use Serrvius\AmqpRpcExtender\Stamp\AmqpRpcQueryStamp;
use Serrvius\AmqpRpcExtender\Interface\AmqpRpcRequestInterface;

class ShowUserQuery  implements AmqpRpcRequestInterface
{

    public function amqpRpcStamp(): AmqpRpcQueryStamp
    {
        return new AmqpRpcQueryStamp('user_queries');
    }



namespace App\UsersModule\Command;

use Serrvius\AmqpRpcExtender\Stamp\AmqpRpcCommandStamp;
use Serrvius\AmqpRpcExtender\Interface\AmqpRpcRequestInterface;

class CreateUserCommand  implements AmqpRpcRequestInterface
{
 
    public function amqpRpcStamp(): AmqpRpcCommandStamp
    {
        return new AmqpRpcCommandStamp('user_create');
    }





namespace App\Command;

use Serrvius\AmqpRpcExtender\Interfaces\AmqpRpcCommandInterface;

class UpdateUserCommand implements AmqpRpcCommandInterface
{


    public static function commandIndex(): string
    {
        return 'user_update';
    }

    protected $commnadData;

    public function setCommandData(array $data): void
    {
        $this->commnadData = $data;
    }




namespace App\Command;

use Serrvius\AmqpRpcExtender\Annotation\AsAmqpRpcCommandExecutor;

#[AsAmqpRpcCommandExecutor(name: 'user_create')]
class CreateUserCommand
{

    public string $id;

    public string $username;

    public string $password;

    public string $firstName;

    public string $lastName;


}




namespace App\Query;


use Serrvius\AmqpRpcExtender\Interfaces\AmqpRpcQueryInterface;

class ShowUserQueryExecutor implements AmqpRpcQueryInterface
{

    public array $data;

    public static function queryIndex(): string
    {
        return "show_user";
    }

    public function setQueryData(array $data): void
    {
        $this->data = $data;
    }





namespace App\Query;

use Serrvius\AmqpRpcExtender\Annotation\AsAmqpRpcQueryExecutor;


#[AsAmqpRpcQueryExecutor(name: 'list_user')]
class ListUserQueryExecutor
{

    protected string $userId;


}



namespace App\Query;

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
class ShowUserQueryHandler
{

    public function __invoke(ShowUserQueryExecutor $query)
    {


        //Do the handler work and return response to gateway 
        
        return $resp;
    }

}

Serrvius\AmqpRpcExtender\Stamp\AmqpRpcQueryStamp

 * php: >=8.1
 * ext-amqp
 * symfony: 6.1.*