[![Build Status](https://travis-ci.org/vladmeh/rabbitmq-client.svg?branch=master)](https://travis-ci.org/vladmeh/rabbitmq-client)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cb2107b6ab3b427cb043a23926e7b4ca)](https://www.codacy.com/gh/vladmeh/rabbitmq-client/dashboard?utm_source=github.com&utm_medium=referral&utm_content=vladmeh/rabbitmq-client&utm_campaign=Badge_Grade)
[![StyleCI](https://github.styleci.io/repos/297304814/shield?branch=master)](https://github.styleci.io/repos/297304814?branch=master)
[![Latest Stable Version](https://poser.pugx.org/vladmeh/rabbitmq-client/v)](//packagist.org/packages/vladmeh/rabbitmq-client)
[![Total Downloads](https://poser.pugx.org/vladmeh/rabbitmq-client/downloads)](//packagist.org/packages/vladmeh/rabbitmq-client)
[![License](https://poser.pugx.org/vladmeh/rabbitmq-client/license)](//packagist.org/packages/vladmeh/rabbitmq-client)
# vladmeh/rabbitmq-client
Wrapper to [php-amqplib](https://github.com/php-amqplib/php-amqplib) library for publishing and consuming [RabbitMQ](https://www.rabbitmq.com/tutorials/tutorial-six-php.html) messages using [Laravel framework](https://laravel.com/docs/master)
## Features
* php v7.*
* [php-amqplib v2.12](https://github.com/php-amqplib/php-amqplib)
* [Laravel from v6.* and above](https://laravel.com/docs/master)
> **PHP8.0 support** will be available after php-amqplib is updated to the next major version 3.0. (https://github.com/php-amqplib/php-amqplib/pull/858)
### Version Compatibility
Laravel | Rabbit Client
:---------|:----------
6.x | 1.x
7.x | 2.x
8.x | --
## Installation
### Composer
```bash
$ composer require vladmeh/rabbit-client
```
or add the following to your requirement part within the composer.json:
```json
{
"require": {
"vladmeh/rabbitmq-client": "^2.*"
}
}
```
> Laravel will automatically register service provider (Vladmeh\RabbitMQ\RabbitMQClientProvider) and facade when is installed
### Configure
Add these properties to .env with proper values:
```dotenv
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
```
If you need advanced configuration properties run:
```bash
$ php artisan vendor:publish --tag=rabbit
```
This command will create a config file `\config\rabbit.php`
## Integration
### Producer
#### Publish a message in the existing queue
```php
Rabbit::publish('message', '', 'queue-name');
```
#### Publish a message in the existing exchange
```php
Rabbit::publish('message', 'exchange-name', 'routing-key');
```
### Publish a message, with custom settings
```php
Rabbit::publish('message', 'amq.fanout', '', [
'hosts' => [
'vhosts' => 'vhost3'
],
'message' => [
'content_type' => 'application/json',
],
'exchange_declare' => [
'type' => 'fanout',
'auto_delete' => true,
]
]);
```
> All default settings are defined in `\config\rabbit.php`.
### Consumer
#### Consume messages to an existing queue
```php
Rabbit::consume('queue-name', function (AMQPMessage $msg) {
$msg->ack();
var_dump($msg->body);
if ($msg->getMessageCount() === null) {
$msg->getChannel()->basic_cancel($msg->getConsumerTag());
}
});
```
### RPC client
```php
$response = Rabbit::rpc('message', 'queue-name', ['connection' => [
'read_write_timeout' => 10.0,
'channel_rpc_timeout' => 10.0
]]);
var_dump($response);
```
蒋叶婷
- 粉丝: 37
- 资源: 4578
最新资源
- 基于神经网络的天牛害虫识别技术开发与设计论文
- 五子棋程序,个人学习整理,仅供参考
- 网络五子棋程序源代码,个人学习整理,仅供参考
- springboot+vue前后端分离项目社区物业管理系统设计与实现源码+数据库
- 基于模型参考自适应的单相脉冲整流器无网压传感器控制方法的复现 使用了传统的Pwm整流器控制方法,只复现了lunwen中的电压估计,角频率估计使用基于sogi的锁相环 估计方案和lunwen基本一致
- 五子棋源程序vc,个人学习整理,仅供参考
- 五子棋源代码代码,个人学习整理,仅供参考
- 视频编码领域的VVC分数插值近似滤波器硬件实现及其低功耗特性研究
- 一个实用的五子棋程序,个人学习整理,仅供参考
- 由于找不到iUtils.dll,无法继续执行代码。重新安装程序可能会解决此问题。
- 汽车二自由度模型和汽车三自由度模型, 本案例采用三种不同方法进行搭建搭汽车线性二自由度simulink模型, 内容包含: 具体的车辆参数数值,详细的设计说明文档,附带关于汽车simulink仿真实例及
- 学生管理系统(SSH+Mysql)
- linux基础知识框架
- 学生信息管理啊系统,个人学习整理,仅供参考
- 基于python实现的爱心代码(python代码)
- 机械设计纽扣装袋输送机creo5.0非常好的设计图纸100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0