PHP code example of cmdrsharp / amqp-route-messenger

1. Go to this page and download the library: Download cmdrsharp/amqp-route-messenger 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/ */

    

cmdrsharp / amqp-route-messenger example snippets


/**
 * @var ClientInterface
 */
protected $client;

/**
 * @param ClientInterface $client
 */
public function __construct(ClientInterface $client)
{
    $this->client = $client;
}

use CmdrSharp\AmqpRouteMessenger\Client;

/**
 * @var ClientInterface
 */
protected $client;

public function __construct()
{
    $this->client = new Client();
}

$instance = $this->client->declareExchange('messages')->publish('correlation_id', 'your message');

// Don't forget to close the channel and connection when done!
$instance->closeChannel()->closeConnection();

$instance = $this->client->declareExchange('messages')
	->declareQueue()
	->bindQueue('correlation_id');

// Note: Reading does freeze the thread until it receives a message.
$message = $instance->read();

// Again, don't forget to close the channel and connection!
$instance->closeChannel()->closeConnection();

$instance = $this->client->declareExchange('messages')
	->declareQueue()
	->bindQueue('correlation_id');

$instance->publish('correlation_id', 'your message');

$message = $instance->read(10); // Optional timeout in seconds.

$instance->closeChannel()->closeConnection();

php artisan vendor:publish --provider="CmdrSharp\AmqpRouteMessenger\AmqpRouteMessengerServiceProvider"