PHP code example of graphaware / php-simplemq

1. Go to this page and download the library: Download graphaware/php-simplemq 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/ */

    

graphaware / php-simplemq example snippets




use GraphAware\SimpleMQ\SimpleMQ;

$smq = SimpleMQ::withYAMLConfigFile(__DIR__.'/path_to_your_config_file.yml');

$consumer = $smq->getConsumer('logs-printer');

$callback = function($message) {
    print_r($message->body);
};

$consumer->consume($callback);

$message = $consumer->getMessage();
// Returns a AMQPMessage instance

$messages = $consumer->getMessageBatch(10);
// Returns an array of AMQPMessage

$messages = $consumer->getMessageBatch(10, 20);

$producer = $smq->getProducer('errors');
$message = json_encode(array('id' => 1234, 'text' => 'Hello world'));

$producer->sendMessage($message);
bash
composer