示例#1
0
 public function testQueueWithPhpSerializer()
 {
     $sendObject = new \stdClass();
     $sendObject->message = "stdClass Message";
     $returnJob = Mockery::mock(JobInterface::class);
     $serializer = new PhpSerializer();
     $adapter = Mockery::mock(AdapterInterface::class);
     $adapter->shouldReceive('enqueue')->once()->with($serializer, $sendObject);
     $adapter->shouldReceive('dequeue')->once()->with($serializer)->andReturn($returnJob);
     $queue = new Queue($serializer, $adapter);
     $queue->enqueue($sendObject);
     $this->assertSame($returnJob, $queue->dequeue());
 }
示例#2
0
文件: sample-sender.php 项目: Wandu/Q
<?php

use Pheanstalk\Pheanstalk;
use Wandu\Q\Adapter\BeanstalkdAdapter;
use Wandu\Q\Adapter\SqsAdapter;
use Wandu\Q\Queue;
use Wandu\Q\Serializer\JsonSerializer;
require __DIR__ . '/../../../vendor/autoload.php';
// SQS Example
//$sender = new Queue(new JsonSerializer(), new SqsAdapter(
//    'AKIAICPQCHQBUDOUZ5FQ',
//    'LVnCpV03Np3mI2h1k9RELuJCZ7FgeSyKZLcZYU4U',
//    'ap-northeast-1',
//    'https://sqs.ap-northeast-1.amazonaws.com/205122141336/gs-queue'
//));
//$sender->enqueue([
//    'body' => 'kkk',
//    '333' => 'halelleknflaksdf',
//]);
$sender = new Queue(new JsonSerializer(), new BeanstalkdAdapter(new Pheanstalk('127.0.0.1')));
$sender->enqueue("???");
示例#3
0
use Wandu\Q\Queue;
use Wandu\Q\Serializer\JsonSerializer;
require __DIR__ . '/../../../vendor/autoload.php';
//$sender = new Queue(new JsonSerializer(), new SqsAdapter(
//    'AKIAICPQCHQBUDOUZ5FQ',
//    'LVnCpV03Np3mI2h1k9RELuJCZ7FgeSyKZLcZYU4U',
//    'ap-northeast-1',
//    'https://sqs.ap-northeast-1.amazonaws.com/205122141336/gs-queue'
//));
//
//while (true) {
//    $job = $sender->dequeue();
//    if (isset($job)) {
//        echo "Receive!\n";
//        print_r($job->read());
//        echo "\n";
//        $job->delete();
//    }
//    sleep(3);
//}
$sender = new Queue(new JsonSerializer(), new BeanstalkdAdapter(new Pheanstalk('127.0.0.1')));
while (true) {
    $job = $sender->dequeue();
    if (isset($job)) {
        echo "Receive!\n";
        print_r($job->read());
        echo "\n";
        $job->delete();
    }
    sleep(3);
}