示例#1
0
    $queue->getContainer()->bind('IronMQ', function () {
        return new IronMQ();
    });
    $queue->addConnection(['driver' => 'iron', 'project' => 'your-project-id', 'token' => 'your-token', 'queue' => 'illuminate-test', 'encrypt' => true]);
    Queue::push('doThing', array('string' => 'iron-' . date('r')));
    echo 'Pushed an instance of doThing to iron.io.';
});
$app->get('/ironio/work/worker', function () use($queue) {
    $queue->getContainer()->bind('request', function () {
        return new Illuminate\Http\Request();
    });
    $queue->getContainer()->bind('IronMQ', function () {
        return new IronMQ();
    });
    $queue->addConnection(['driver' => 'iron', 'project' => 'your-project-id', 'token' => 'your-token', 'queue' => 'illuminate-test', 'encrypt' => true]);
    $worker = new \Illuminate\Queue\Worker($queue->getQueueManager());
    //	Params list for 'pop':
    //	  * Name of the connection to use--you can define a unique connection name by passing a second parameter to addConnection above
    //	  * Name of the queue to use--this is the value for the 'queue' key in addConnection
    //	  * Number of seconds to delay a job if it fails
    //	  * Maximum amount of memory to use
    //	  * Time (in seconds) to sleep when no job is returned
    //	  * Maximum number of times to retry the specific job item before discarding it
    while (true) {
        try {
            $worker->pop('default', 'illuminate-test', 3, 64, 30, 3);
        } catch (\Exception $e) {
            // Handle job exception
        }
    }
});
<?php

require_once __DIR__ . "/vendor/autoload.php";
use Illuminate\Http\Request;
use Illuminate\Queue\Capsule\Manager as Capsule;
use Orlissenberg\Queue\Connectors\ZendJobQueueConnector;
$capsule = new Capsule();
/** @var \Illuminate\Queue\QueueManager $manager */
$manager = $capsule->getQueueManager();
$app = $capsule->getContainer();
$app->bind("encrypter", function () {
    return new Illuminate\Encryption\Encrypter("test");
});
$app->bind("request", function () {
    return Request::createFromGlobals();
});
// Add a new connector
$manager->extend("zendserver", function () use($app) {
    return new ZendJobQueueConnector($app['encrypter'], $app['request']);
});
// Add a connection by the name of "zend"
$capsule->addConnection(['driver' => 'zendserver', 'options' => [], 'callback-url' => 'http://jobqueue.dev/tests/receive.php'], 'zend');
// A driver requires configuration?
$capsule->setAsGlobal();