定制 slm/queue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slm/queue

最新稳定版本:3.3.0

Composer 安装命令:

composer require slm/queue

包简介

Laminas module that integrates with various queue management systems

README 文档

README

SlmQueue

Important notice

We decided to move onto Symfony Messenger and we are therefore not maintaining this repository anymore. Feel free to fork it and make it your own.

Latest Stable Version

SlmQueue is a job queue abstraction layer for Laminas (formerly Zend Framework) and Mezzio (formerly Zend Expressive) applications. It supports various job queue systems and makes your application independent from the underlying system you use. The currently supported systems have each their own adapter library:

When to use

A job queue helps to offload long or memory-intensive processes from the HTTP requests clients sent to the Laminas application. This will make your response times shorter and your visitors happier. There are many use cases for asynchronous jobs and a few examples are:

  1. Send an email
  2. Create a PDF file
  3. Connect to a third party server over HTTP

In all cases you want to serve the response as soon as possible to your visitor, without letting them wait for this long process. SlmQueue enables you to implement a job queue system very easily within your existing application.

Installation

SlmQueue works with Composer. Make sure you have the composer.phar downloaded and you have a composer.json file at the root of your project. To install it, add the following line into your composer.json file:

"require": {
    "slm/queue": "^3.0"
}

After installation of the package, you need to complete the following steps to use SlmQueue:

  1. Enable the module by adding SlmQueue in your application.config.php file.
  2. Copy the slm_queue.global.php.dist (you can find this file in the config folder of SlmQueue) into your config/autoload folder and apply any setting you want.

NB. SlmQueue is a skeleton and therefore useless by itself. Enable an adapter to give you the implementation details you need to push jobs into the queue. Install one of the available adapters (SlmQueueDoctrine, SlmQueueRabbitMq, or SlmQueueSqs).

Requirements

Code samples

Below are a few snippets which show the power of SlmQueue in your application. The full documentation is available in docs/ directory.

A sample job to send an email with php's mail() might look like this:

namespace MyModule\Job;

use SlmQueue\Job\AbstractJob;

class EmailJob extends AbstractJob
{
    public static function create(string $to, string $subject, string $message): self
    {
        // This will bypass the constructor, and thus load a job without
        // having to load the dependencies.
        $job = self::createEmptyJob([
            'subject' => $subject,
            'to' => $to,
            'message' => $message,
        ]);

        // Add some metadata, so we see what is going on.
        $job->setMetadata('to', $to);

        return $job;
    }

    private SomeMailService $mailService;

    public function __construct(SomeMailService $mailService)
    {
        $this->mailService = $mailService;
    }

    public function execute()
    {
        $payload = $this->getContent();

        $to      = $payload['to'];
        $subject = $payload['subject'];
        $message = $payload['message'];

        $this->mailService->send($to, $subject, $message);
    }
}

If you want to inject this job into a queue, you can do this for instance in your controller:

namespace MyModule\Controller;

use MyModule\Job\Email as EmailJob;
use SlmQueue\Queue\QueueInterface;
use Laminas\Mvc\Controller\AbstractActionController;

class MyController extends AbstractActionController
{
    protected $queue;

    public function __construct(QueueInterface $queue)
    {
        $this->queue = $queue;
    }

    public function fooAction()
    {
        // Do some work

        $this->queue->push(
            EmailJob::create('john@doe.com', 'Just hi', 'Hi, I want to say hi!'),
            ['delay' => 60]
        );
    }
}

Now the above code lets you insert jobs in a queue, but then you need to spin up a worker which can process these jobs.

SlmQueue integrates with laminas-cli for command line usage. You can start up a worker for queue "default" with the following command:

$ vendor/bin/laminas slm-queue:start default

Contributing

SlmQueue is developed by various fanatic Laminas users. The code is written to be as generic as possible for Laminas applications. If you want to contribute to SlmQueue, fork this repository and start hacking!

Any bugs can be reported as an issue at GitHub. If you want to contribute, please be aware of the following guidelines:

  1. Fork the project to your own repository
  2. Use branches to work on your own part
  3. Create a Pull Request at the canonical SlmQueue repository
  4. Make sure to cover changes with the right amount of unit tests
  5. If you add a new feature, please work on some documentation as well

For long-term contributors, push access to this repository is granted.

Who to thank?

Jurian Sluiman and Michaël Gallego did the initial work on creating this repo, and maintained it for a long time.

Currently it is maintained by:

slm/queue 适用场景与选型建议

slm/queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 796.35k 次下载、GitHub Stars 达 138, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「job」 「laminas」 「mezzio」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 slm/queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 slm/queue 我们能提供哪些服务?
定制开发 / 二次开发

基于 slm/queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 796.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 143
  • 点击次数: 41
  • 依赖项目数: 14
  • 推荐数: 1

GitHub 信息

  • Stars: 138
  • Watchers: 15
  • Forks: 55
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 未知