[![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);
```
没有合适的资源?快使用搜索试试~ 我知道了~
Rabbitmq客户端
共20个文件
php:13个
yml:3个
json:1个
需积分: 0 1 下载量 86 浏览量
2021-02-11
19:01:55
上传
评论
收藏 13KB ZIP 举报
温馨提示
vladmeh / rabbitmq-client 包装到库,以使用发布和使用消息 产品特点 php v7。* 将php-amqplib更新到下一个主要版本3.0后,将提供PHP8.0支持。 ( ) 版本兼容性 Laravel 兔子客户端 6.x 1.x 7.x 2.x 8.x - 安装 作曲家 $ composer require vladmeh/rabbit-client 或将以下内容添加到composer.json中的需求部分: { " require " : { " vladmeh/rabbitmq-client " : " ^2.* " } } Laravel将在安装后自动注册服务提供商(Vladmeh \ RabbitMQ \ RabbitMQClientProvider)和外观 配置 使用适当的值将这些属性添加到.env中
资源详情
资源评论
资源推荐
收起资源包目录
rabbitmq-client-master.zip (20个子文件)
rabbitmq-client-master
composer.json 1KB
.travis.yml 649B
phpunit.xml 603B
config
rabbit.php 1KB
tests
Services
RpcTest.php 960B
ProducerTest.php 2KB
ConsumerTest.php 2KB
TestCase.php 558B
src
RabbitMQClientProvider.php 640B
Services
Rpc.php 2KB
Consumer.php 2KB
Producer.php 677B
AbstractRabbit.php 4KB
Facades
Rabbit.php 629B
Rabbit.php 1KB
Contracts
RpcClient.php 275B
docker-compose.yml 211B
.gitignore 68B
.styleci.yml 89B
README.md 3KB
共 20 条
- 1
蒋叶婷
- 粉丝: 36
- 资源: 4578
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0