GithubHelp home page GithubHelp logo

redis-queue's Introduction

redis-queue

Message queue system written in PHP based on workerman and backed by Redis.

Install

composer require workerman/redis-queue

Usage

test.php

<?php
require __DIR__ . '/vendor/autoload.php';

use Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\RedisQueue\Client;

$worker = new Worker();
$worker->onWorkerStart = function () {
    $client = new Client('redis://127.0.0.1:6379');

    $client->subscribe('user-1', function($data) {
        echo "user-1\n";
        var_export($data);
    });

    $client->subscribe('user-2', function($data) {
        echo "user-2\n";
        var_export($data);
    });

    $client->onConsumeFailure(function (\Throwable $exception, $package) {
        echo "consume failure\n";
        echo $exception->getMessage(), "\n";
        var_export($package);
    });

    Timer::add(1, function() use ($client) {
        $client->send('user-1', ['some', 'data']);
    });
};

Worker::runAll();

Run with command php test.php start or php test.php start -d.

API


__construct (string $address, [array $options])

Create an instance by $address and $options.

  • $address for example redis://ip:6379.

  • $options is the client connection options. Defaults:

    • auth: default ''
    • db: default 0
    • retry_seconds: Retry interval after consumption failure
    • max_attempts: Maximum number of retries after consumption failure

send(String $queue, Mixed $data, [int $dely=0])

Send a message to a queue

  • $queue is the queue to publish to, String
  • $data is the message to publish, Mixed
  • $dely is delay seconds for delayed consumption, Int

subscribe(mixed $queue, callable $callback)

Subscribe to a queue or queues

  • $queue is a String queue or an Array which has as keys the queue name to subscribe.
  • $callback - function (Mixed $data), $data is the data sent by send($queue, $data).

unsubscribe(mixed $queue)

Unsubscribe from a queue or queues


onConsumeFailure(callable $callback)

When consumption fails onConsumeFailure is triggered.

  • $callback - function (\Throwable $exception, array $package), $package contains information such as data queue attempts

redis-queue's People

Contributors

krissss avatar latypoff avatar walkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

redis-queue's Issues

如何优雅抛出异常而不堆栈存出redis中?

throw new \Excption('异常');
这样异常给redis弄了一堆报错打印

尝试以下操作

1. config/app.php

debug=>false
error_reporting=>1024

这个是webman的错误打印配置

2.尝试使用trigger_error("超时重试2",E_USER_NOTICE)

还是会打印错误堆栈

找寻源码 webman/queue 是对 workerman/redis-queue的优雅封装,搞不定

因为我已经选择主动抛出异常重试,堆栈信息是否保存到redis起码可选的吧~ redis - fail表体积爆炸

how to call `Gateway::sendToGroup` in redis-queue?

i start redis-queue as a stanelone service process, in subscriber's callback call Gateway::sendToGroup(someGroup) it doesn't work...

i also try Gateway::$registerAddress = 'xxxx'

do you know how?

pls let me know. thanks!

建议增加class

subscribe方法目前只能用callable,建议增加可用class方法调用

QUEUE_WAITING、QUEUE_DELAYED、QUEUE_FAILED可自定义

部署新机器的时候突然发现不兼容修改

v1.0.3 - v1.0.9之间为什么会修改到队列名的前缀呢
由于使用队列和其他的系统进行了通信,底层的队列名前缀修改后相当于我只是升级了个版本,系统之间的通信却断了,当时定位了很久🤣
(PS:没有其他意思哈,因为没有太细追源码,比较好奇这个修改的初衷)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.