[![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);
```
蒋叶婷
- 粉丝: 36
- 资源: 4578
最新资源
- Python 版官方 Dropbox API V2 SDK.zip
- solidworks焊件槽钢多配置库,一个文件包含所有配置,可用于结构系统,2016以上版本可以打开使用
- jenkins2.346.1最后一版支持java8的jenkins插件
- gcc和clang编译选项总结
- CATICS3D1-18届图纸练习三维二维造型学习建模素材
- CaTICs网络3D大赛-1~8届所有题目建模模型(prt文件)-个人建模,UG8.0以上版本可以打开 观看建模步骤
- linux内核编码风格总结
- 图像识别技术在智能安防、零售、医疗与自动驾驶领域的深度学习应用与实现
- 基于JavaWeb的学生社团信息管理系统源码+数据库脚本.zip
- Python-图片去重工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0