imatic/notification
Composer 安装命令:
composer require imatic/notification
包简介
Simple library for sending reliable messages among apps
README 文档
README
Imatic Notification
Application for simplifying using message queues
Configuration
Library needs 2 configuration options to by specified by you. How to specify them depends on your service container (see Acessing to the services section).
- imatic_notification_params
- parameters of the connection to the broker
<?php $params = [ 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'namespace' => '', ];
- imatic_notification.logger
- logger implementing interface of psr log
- in our examples below, we did use NullLogger, which will log nothing - we highly discourage from usage if this logger in production since you'll have no Idea what went wrong if something wrong happend
Interface of the library
You will work with 2 interfaces Publisher for publishing messages into queues and Consumer to consume messages published by publisher.
<?php namespace Imatic\Notification; interface Connection { public function createPublisher(ChannelParams $params); public function createConsumer(ChannelParams $params); } interface Publisher { public function publish(Message $message, $key = ''); } interface Consumer { public function consume($queueName, $key, callable $callback); public function wait(); public function waitN($n); }
These 2 interfaces are implemented by service imatic_notification.connection
Accessing to the services
It is advised to use one container to create connection object for you from definition file "config/services.yml". Below you can see 2 of many possible ways to go.
Using Symfony
To load services for Symfony, you need to edit your your app/config/config.yml
imports: - { resource: ../../vendor/imatic/notification/config/services.yml } parameters: imatic_notification_params: [] services: imatic_notification.logger: class: Psr\Log\NullLogger
And then you can access to the services from your Symfony container
<?php $connection = $this->container->get('imatic_notification.connection');
Usage example
<?php // create connection to the broker $connection = $this->container->get('imatic_notification.connection'); // create channel parameters $channelParams = new ChannelParams($exchange = 'imatic_queue_test'); // create consumer $consumer = $connection->createConsumer($channelParams); // listen to the messages on queue "queue_name" // to all messages having routing key "routing_key" $consumer->consume('queue_name', 'routing_key', function (Message $msg) { $this->logger->logData('data'); // you need to return true to tell the broker that it can discard the messaga // because you successfully processed it return true; }); // create publisher $publisher = $connection->createPublisher($channelParams); // publish message to the channel with routing key "routing_key" $publisher->publish(new Message(['data' => 'bdy']), 'routing_key'); // consume only 1 message, then continue $consumer->waitN(1); // won't return till you have listening consumers $consumer->wait();
imatic/notification 适用场景与选型建议
imatic/notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.69k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 imatic/notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imatic/notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-07