承接 hyperlab/laravel-pubsub-rabbitmq 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

hyperlab/laravel-pubsub-rabbitmq

Composer 安装命令:

composer require hyperlab/laravel-pubsub-rabbitmq

包简介

An opinionated approach to implement Pub/Sub messaging in Laravel using RabbitMQ.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides an opinionated approach to implement Pub/Sub messaging in Laravel using RabbitMQ.

Installation

Install the package via composer:

composer require hyperlab/laravel-pubsub-rabbitmq

Publish the config/pubsub.php config file:

php artisan vendor:publish --provider="Hyperlab\LaravelPubSubRabbitMQ\PubSubServiceProvider" --tag="pubsub-rabbitmq-config"

Publish the routes/subscriptions.php routes file:

php artisan vendor:publish --provider="Hyperlab\LaravelPubSubRabbitMQ\PubSubServiceProvider" --tag="pubsub-rabbitmq-subscriptions"

Add the following snippet to your application's config/queue.php file.

<?php

return [

    // ...

    'connections' => [

        // ...
        
        'pubsub' => [
            'driver' => 'pubsub',
            'hosts' => [
                [
                    'host' => env('RABBITMQ_HOST', '127.0.0.1'),
                    'port' => env('RABBITMQ_PORT', 5672),
                    'user' => env('RABBITMQ_USER', 'guest'),
                    'password' => env('RABBITMQ_PASSWORD', 'guest'),
                    'vhost' => env('RABBITMQ_VHOST', '/'),
                ],
            ],
            'options' => [
                'ssl_options' => [
                    'cafile' => env('RABBITMQ_SSL_CAFILE'),
                    'local_cert' => env('RABBITMQ_SSL_LOCALCERT'),
                    'local_key' => env('RABBITMQ_SSL_LOCALKEY'),
                    'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
                    'passphrase' => env('RABBITMQ_SSL_PASSPHRASE'),
                ],
            ],
        ],

    ],
    
    // ...
    
];

More details about the configuration options for the queue connection can be found in the readme of the vyuldashev/laravel-queue-rabbitmq package.

Configuration

You can configure the package to suit your needs through the config/pubsub.php config file. By default, the file looks like this:

<?php

return [

    'rabbitmq' => [

        /*
         * The name of the RabbitMQ exchange on which the outgoing messages are published.
         */
        'exchange' => env('PUBSUB_RABBITMQ_EXCHANGE'),

        /*
         * The name of the RabbitMQ queue from which the incoming messages are consumed.
         */
        'queue' => env('PUBSUB_RABBITMQ_QUEUE'),

    ],

    'queue' => [

        /*
         * The queue connection that is used to communicate with RabbitMQ.
         */
        'connection' => env('PUBSUB_QUEUE_CONNECTION', 'pubsub'),
        
        /*
         * The queue worker that you want to consume your incoming messages with.
         *
         * Valid options are: default, horizon
         */
        'worker' => env('PUBSUB_QUEUE_WORKER', 'default'),

    ],

    /*
     * The file within your code base that contains the message subscriptions of your application.
     */
    'subscriptions' => base_path('routes/subscriptions.php'),

];

Subscribers

In order for your application to receive messages from RabbitMQ, it needs to subscribe to one or more message types.

By default, these subscriptions can be defined in the routes/subscriptions.php file. However, the path to this file can be changed in the configuration file.

The contents of the subscriptions file should look like this:

<?php

return [

    'user.created' => HandleUserCreatedMessage::class,

    'user.deleted' => [HandleUserDeletedMessage::class, 'handle'],

];

The file returns an associative array in which:

  • a key represents a type of messages that the application wants to receive
  • a value represents the class within your application that handles the incoming message of this type

The handler of a subscription can be defined in two ways:

  1. By referencing a class

    'user.created' => HandleUserCreatedMessage::class,

    In this case, the package looks for a public method in the class that accepts a Hyperlab\LaravelPubSubRabbitMQ\Subscriber\Message as argument. This method can be called anything, as shown here:

    class HandleUserCreatedMessage
    {
        public function __invoke(\Hyperlab\LaravelPubSubRabbitMQ\Subscriber\Message $message): void
        {
            //
        }
    }
    
    class HandleUserCreatedMessage
    {
        public function handle(\Hyperlab\LaravelPubSubRabbitMQ\Subscriber\Message $message): void
        {
            //
        }
    }
    
    class HandleUserCreatedMessage
    {
        public function execute(\Hyperlab\LaravelPubSubRabbitMQ\Subscriber\Message $message): void
        {
            //
        }
    }
  2. By referencing a class and method

    'user.created' => [HandleUserCreatedMessage::class, 'handle'],

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

hyperlab/laravel-pubsub-rabbitmq 适用场景与选型建议

hyperlab/laravel-pubsub-rabbitmq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.68k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-16