Exemple #1
0
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$config = (require_once __DIR__ . '/../config.php');
$adapter = new \Amqp\Adapter\AmqplibAdapter($config);
$msg = new \Amqp\Message();
$msg->setDeliveryMode(2);
$msg->setHeaders(['x-foo' => 'sfgsd']);
$msg->setPayload(uniqid());
$adapter->publish('global', $msg);
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$config = (require_once __DIR__ . '/../config.php');
$msg = new \Amqp\Message();
$msg->setDeliveryMode(2);
$msg->setHeaders(['x-foo' => 'sfgsd']);
$msg->setPayload(uniqid());
$adapter = new \Amqp\Adapter\AmqplibAdapter($config);
$adapter->publish('global', $msg);
$adapter->listen('debug', function (\Amqp\Message\MessageInterface $message, \Amqp\Message\Result $result) {
    echo $message->getPayload(), PHP_EOL;
    // not cool, but you can requeue
    return $result->requeue()->nack();
});
Exemple #3
0
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$config = (require_once __DIR__ . '/../config.php');
$adapter = new \Amqp\Adapter\AmqplibAdapter($config);
$msg = new \Amqp\Message();
$msg->setDeliveryMode(2);
$msg->setHeaders(['x-foo' => 'sfgsd']);
$msg->setPayload(uniqid());
for ($i = 3; $i--;) {
    $adapter->publish('global', $msg);
}
$adapter->listen('debug', function (\Amqp\Message\MessageInterface $message, \Amqp\Message\Result $result) {
    echo $message->getPayload(), PHP_EOL;
    return $result->ack();
});
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$config = (require_once __DIR__ . '/../config.php');
$adapter = new \Amqp\Adapter\AmqplibAdapter($config);
for ($i = 3; $i--;) {
    $msg = new \Amqp\Message();
    $msg->setDeliveryMode(2);
    $msg->setHeaders(['x-foo' => 'sfgsd']);
    $msg->setPayload(uniqid());
    $adapter->publish('global', $msg);
}
$counter = 0;
$adapter->listen('debug', function (\Amqp\Message\MessageInterface $message, \Amqp\Message\Result $result) use(&$counter) {
    echo $message->getPayload(), PHP_EOL;
    $result->ack();
    // process only 2 messages
    if (++$counter === 2) {
        return $result->stop();
    }
});