定制 cmdrsharp/amqp-route-messenger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cmdrsharp/amqp-route-messenger

Composer 安装命令:

composer require cmdrsharp/amqp-route-messenger

包简介

A client for publishing and listening for routed exchange messages.

README 文档

README

Latest Stable Version Build Status StyleCI Scrutinizer Code Quality MIT licensed

A client for publishing and listening for routed exchange messages.

Current Requirements

  • PHP 7.2 or newer
  • Laravel 5.8 or newer

Installation

Via composer

$ composer require cmdrsharp/amqp-route-messenger

After installation, publish the configuration file.

php artisan vendor:publish --provider="CmdrSharp\AmqpRouteMessenger\AmqpRouteMessengerServiceProvider"

Which will create a amqproutemessenger.php file in your Laravel config directory. This will contain bindings for the RabbitMQ Queue Details. It is recommended to simply define these in your .env file. The config file will automatically read from these values.

RABBITMQ_HOST=
RABBITMQ_PORT=5672
RABBITMQ_VHOST=/
RABBITMQ_LOGIN=
RABBITMQ_PASSWORD=

For SSL Connections, just specify (in your .env file) the path to the CA Certificate, and whether to use peer verification. If these are specified, an AMQPSSLConnection will be established.

RABBITMQ_CA_FILE="/path/to/yourca.crt"
RABBITMQ_VERIFY_PEER=true

Usage

Inject the contract into the class where you need the client:

/**
 * @var ClientInterface
 */
protected $client;

/**
 * @param ClientInterface $client
 */
public function __construct(ClientInterface $client)
{
    $this->client = $client;
}

Alternatively, if you don't wish to autoload, you may also require it directly.

use CmdrSharp\AmqpRouteMessenger\Client;

/**
 * @var ClientInterface
 */
protected $client;

public function __construct()
{
    $this->client = new Client();
}

Example: Publish a message with a correlation ID

All we are doing here is declaring which exchange to publish the message to, and then publishing it with a specified correlation ID. declareExchange accepts an optional second parameter which makes it passive

$instance = $this->client->declareExchange('messages')->publish('correlation_id', 'your message');

// Don't forget to close the channel and connection when done!
$instance->closeChannel()->closeConnection();

Example: Read a message with a correlation ID

It is recommended that the consumer is set up prior to any messages being published. This is to ensure that the queue bindings have been created, so that published messages are routed correctly.

$instance = $this->client->declareExchange('messages')
	->declareQueue()
	->bindQueue('correlation_id');

// Note: Reading does freeze the thread until it receives a message.
$message = $instance->read();

// Again, don't forget to close the channel and connection!
$instance->closeChannel()->closeConnection();

Example: Reading and Publishing put together

$instance = $this->client->declareExchange('messages')
	->declareQueue()
	->bindQueue('correlation_id');

$instance->publish('correlation_id', 'your message');

$message = $instance->read(10); // Optional timeout in seconds.

$instance->closeChannel()->closeConnection();

Versioning

This package follows Explicit Versioning.

Authors

CmdrSharp

License

The MIT License (MIT)

cmdrsharp/amqp-route-messenger 适用场景与选型建议

cmdrsharp/amqp-route-messenger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 cmdrsharp/amqp-route-messenger 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-05