1. Go to this page and download the library: Download mucy/webman-rabbitmq 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/ */
declare(strict_types=1);
namespace process\workbunny\rabbitmq;
use Bunny\Channel as BunnyChannel;
use Bunny\Async\Client as BunnyClient;
use Bunny\Message as BunnyMessage;
use Workbunny\WebmanRabbitMQ\Constants;
use Workbunny\WebmanRabbitMQ\FastBuilder;
class TestBuilder extends FastBuilder
{
// QOS 大小
protected int $prefetch_size = 0;
// QOS 数量
protected int $prefetch_count = 0;
// QOS 是否全局
protected bool $is_global = false;
// 是否延迟队列
protected bool $delayed = false;
// 消费回调
public function handler(BunnyMessage $message, BunnyChannel $channel, BunnyClient $client): string
{
// TODO 消费需要的回调逻辑
var_dump('请重写 TestBuilderDelayed::handler() ');
return Constants::ACK;
# Constants::NACK
# Constants::REQUEUE
}
}
use function Workbunny\WebmanRabbitMQ\sync_publish;
use process\workbunny\rabbitmq\TestBuilder;
sync_publish(TestBuilder::instance(), 'abc'); # return bool
use function Workbunny\WebmanRabbitMQ\sync_publish;
use process\workbunny\rabbitmq\TestBuilder;
sync_publish(TestBuilder::instance(), 'abc', [
'x-delay' => 10000, # 延迟10秒
]); # return bool
use function Workbunny\WebmanRabbitMQ\async_publish;
use process\workbunny\rabbitmq\TestBuilder;
async_publish(TestBuilder::instance(), 'abc'); # return PromiseInterface|bool
use function Workbunny\WebmanRabbitMQ\async_publish;
use process\workbunny\rabbitmq\TestBuilder;
async_publish(TestBuilder::instance(), 'abc', [
'x-delay' => 10000, # 延迟10秒
]); # return PromiseInterface|bool