PHP code example of alchemy / queue-component

1. Go to this page and download the library: Download alchemy/queue-component 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/ */

    

alchemy / queue-component example snippets


// Note: the following array contains all available parameters and their default values
// Every configuration key is optional, and its default value used when not defined in parameters
$parameters = [
    'host' => 'localhost',
    'vhost' => '/',
    'port' => 5672,
    'user' => 'guest',
    'password' => 'guest',
    'exchange' => 'alchemy-exchange',
    'dead-letter-exchange' => 'alchemy-dead-exchange',
    'queue' => 'alchemy-queue'
];

$factory = Alchemy\Queue\Amqp\AmqpMessageQueueFactory::create($parameters);

// Publish a message
$factory->getNamedQueue('my-queue')->publish(new Message('message body', 'correlation-id'));

// Consume next message in queue
$handler = new Alchemy\Queue\NullMessageHandler();
$resolver = new Alchemy\Queue\MessageHandlerResolver($handler);
$factory->getNamedQueue('my-queue')->handle($resolver);