PHP code example of workbunny / webman-rqueue

1. Go to this page and download the library: Download workbunny/webman-rqueue 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/ */

    

workbunny / webman-rqueue example snippets


    /*
     * Builder 启动时
     *
     * @param Worker $worker
     * @return void
     */
    abstract public function onWorkerStart(Worker $worker): void;

    /**
     * Builder 停止时
     *
     * @param Worker $worker
     * @return void
     */
    abstract public function onWorkerStop(Worker $worker): void;

    /**
     * Builder 重加载时
     *
     * @param Worker $worker
     * @return void
     */
    abstract public function onWorkerReload(Worker $worker): void;

    /**
     * Command 获取需要创建的类文件内容
     *
     * @param string $namespace
     * @param string $className
     * @param bool $isDelay
     * @return string
     */
    abstract public static function classContent(string $namespace, string $className, bool $isDelay): string;

use function Workbunny\WebmanRqueue\sync_publish;
use function Workbunny\WebmanRqueue\sync_publish_get_ids;
use process\workbunny\rqueue\TestBuilder;

# 使用函数发布,返回受影响条数,多队列不具备事务一致
/** headers参数详见 @link Header */
sync_publish(TestBuilder::instance(), 'abc', [
	'_delete' => false
]);

# 使用对象发布,返回受影响条数,多队列不具备事务一致
/** headers参数详见 @link Header */
TestBuilder::instance()->publish('abc', [
	'_delete' => false
]);

# 返回消息ID组(数组),多队列不具备事务一致
sync_publish_get_ids(TestBuilder::instance(), 'abc', [
	'_delete' => false
]);

# 返回消息ID组(数组),多队列不具备事务一致
TestBuilder::instance()->publishGetIds('abc', [
	'_delete' => false
]);

use function Workbunny\WebmanRqueue\sync_publish;
use function Workbunny\WebmanRqueue\sync_publish_get_ids;
use process\workbunny\rqueue\TestBuilder;

# 延迟10ms,返回受影响条数,多队列不具备事务一致
sync_publish(TestBuilder::instance(), 'abc', [
	'_delay' => 10
]);

# 延迟10ms,返回受影响条数,多队列不具备事务一致
TestBuilder::instance()->publish('abc', [
	'_delay' => 10
]);

# 延迟10ms,返回消息ID组(数组),多队列不具备事务一致
sync_publish_get_ids(TestBuilder::instance(), 'abc', [
	'_delay' => 10
]);

# 延迟10ms,返回消息ID组(数组),多队列不具备事务一致
TestBuilder::instance()->publishGetIds('abc', [
	'_delay' => 10
]);