定制 t3n/jobqueue-rabbitmq 二次开发

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

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

t3n/jobqueue-rabbitmq

Composer 安装命令:

composer require t3n/jobqueue-rabbitmq

包简介

A Flowpack.JobQueue.Common implementation to support RabbitMQ as backend

README 文档

README

CircleCI Latest Stable Version Total Downloads

t3n.JobQueue.RabbitMQ

A job queue backend for the Flowpack.JobQueue.Common package based on RabbitMQ. If you don't know anything about RabbitMQ yet have a look at their tutorials here.

Disclaimer: This is a fork/remake of an initial version which was made by ttreeagency!

Setup

To use RabbitMQ as a backend for a JobQueue you need a running RabbitMQ Service. You can use our docker image which also includes the management console t3n/rabbitmq

Install the package using composer:

composer require t3n/jobqueue-rabbitmq

Configuration

RabbitMQ allows a wide range of configuration and setups. Have a look at Settings.yaml for an overview with all available configuration options.

The simplest configuration for a job queue could look like this:

Flowpack:
  JobQueue:
    Common:
      queues:
        simple-queue:
          className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
          executeIsolated: true

          options:
            queueOptions:
              # we want the queue to persist messages so they are stored even if no consumer (aka worker) is connected
              durable: true
              # multiple worker should be able to consume a queue at the same time
              exclusive: false
              autoDelete: false

            client:
              host: localhost
              port: 5672
              username: guest
              password: guest

A more complex configuration could also configure an exchange and some routing keys. In this example we will configure one exchange which all producers connect to. If your RabbitMQ server has the rabbitmq_delayed_message_exchange plugin (our docker image ships it by default) enabled we can also use the delay feature.

This configuration will configure several queues for one exchange. Message are routed to the queue based on a routingKey. We will use three parts for it: <project>.<type>.<name>. We will use the type job to indicate it's a job to execute. We could also use something like log or whatever. The shape of the routing key is up to you!

So after all we will configure several producers/job queues. The producer queues are meant to be used with $jobManager->queue(). The consumer queue will be used within the ./flow job:work command.

In this example we will end up with two queues. One queue with all messages matching the routing key vendor.jobs.*, so whenever the producer-import or producer-tags queue is used the message will end up in this queue. And another queue that fetches all jobs for all vendors.

To actually start a consumer run ./flow job:work --queue all-jobs.

This pattern enables you to implement different kind of advanced pub/sup implementations.

Flowpack:
  JobQueue:
    Common:
      presets:
        rabbit:
          className: 't3n\JobQueue\RabbitMQ\Queue\RabbitQueue'
          executeIsolated: true
          maximumNumberOfReleases: 3

          releaseOptions:
            delay: 5

          options:
            routingKey: ''
            useDLX: true # enable support for dead letter exchange, requires configuration in RabbitMQ

            queueOptions:
              # don't declare a queue by default
              # all messages are forwarded to the exchange "t3n"
              declare: false
              exchangeName: 't3n'
              # the queue should be durable and don't delete itself
              durable: true
              autoDelete: false
              # several worker are allowed per queue
              exclusive: false

            exchange:
              name: 't3n'
              # this exchange should support delayed messages
              type: 'x-delayed-message'
              passive: false
              durable: true
              autoDelete: false
              arguments:
                # the origin type is topic so we can use routingkeys including `*` or `#`
                x-delayed-type: 'topic'

            client:
              host: localhost
              port: 5672
              username: guest
              password: guest
              heartbeat: 60 # Sets RabbitMQ connection heartbeat to 60 seconds

      queues:
        producer-import:
          preset: rabbit
          options:
            routingKey: 'vendor.jobs.import'

        producer-tags:
          preset: rabbit
          options:
            routingKey: 'vendor.jobs.tags'

        vendor-jobs:
          preset: rabbit
          options:
            routingKey: 'vendor.jobs.*'
            queueOptions:
              # this queue should actually be declared
              declare: true

        all-jobs:
          preset: rabbit
          options:
            routingKey: '*.jobs.*'
            queueOptions:
              # this queue should actually be declared
              declare: true

t3n/jobqueue-rabbitmq 适用场景与选型建议

t3n/jobqueue-rabbitmq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 322.87k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 t3n/jobqueue-rabbitmq 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 7
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-23