channext/channext-rabbitmq 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

channext/channext-rabbitmq

最新稳定版本:1.8.1

Composer 安装命令:

composer require channext/channext-rabbitmq

包简介

The RabbitMQ integration for Channext services

README 文档

README

A Laravel x RabbitMQ integration is a package to simplify the publishing and consuming of messages to and from a RabbitMQ server. This package expects you to use a topic exchange and bases its routing on the messages' routing keys.

Installation

  1. Run composer require channext/channext-rabbitmq in the root of your project
  2. Run php artisan vendor:publish and choose the option "Provider: Channext\ChannextRabbitmq\Providers\RabbitMQServiceProvider"
  3. If you want to use RabbitMQAuth facade and run php artisan vendor:publish then choose the option "Provider: Channext\ChannextRabbitmq\Providers\EventAuthServiceProvider"
  4. Implement your logic inside EventAuthServiceProvider boot()
  5. If you want to use EventFail provider facade and run php artisan vendor:publish then choose the option "Provider: Channext\ChannextRabbitmq\Providers\EventFailServiceProvider"
  6. Implement your logic inside EventFailServiceProvider boot()
  7. Add the correct RabbitMQ credentials to your .env file (see config/rabbitmq.php for the available variables. Also be sure to use different queue names for different services, otherwise only one service will act on the event other ones will miss it.)
  8. Run php artisan config:cache
  9. Run php artisan cache:clear
  10. Update the routes/topics.php file with the routes you want to listen to
  11. Run php artisan rabbitmq:consume to start consuming messages. Or you can use php artisan rabbitmq:listen to listen & consume every event in a separate app container. (This is more suitable for development purposes, but a bit slower.)

Examples

This package enables you to use a facade for executing simple publishing and consuming of RabbitMQ messages. To start using the facade simply import it in the class where you want to use it:
use Channext\ChannextRabbitmq\Facades\RabbitMQ;

To publish a message simply use the publish method in the RabbitMQ facade:
RabbitMQ::publish($body, $routingKey);
Where the body parameter is the data that you want to send and the routing key is the route that consumers can listen to. E.g. the moment a user is created the body should contain all the user data and the routing key could be "user.created".

To start consuming messages you should update the routes/topics.php file with all the routing keys you want your service to listen to. This is actually very similar to the way Laravel usually handles routing:
RabbitMQ::route('user.login', [Controller::class, 'test'], retry: false);
This route would only listen to messages with a routing key "user.login" and would execute the "test"-method in the controller.

The functions in the controllers called by the router should always accept the message as the first parameter:
public function test(AMQPMessage $message) { $messageBody = $message->all(); }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-09-29