eonx-com/easy-notification
Composer 安装命令:
composer require eonx-com/easy-notification
包简介
Client for dispatching notifications at EonX
README 文档
README
---eonx_docs--- title: Introduction weight: 0 ---eonx_docs---
This package is made to ease dispatching notifications within EonX Notification service, and works with this service ONLY.
Require package (Composer)
The recommended way to install this package is to use Composer:
$ composer require eonx-com/easy-notification
Configuration
In order to send notifications using the EonX Notification service, you need to register a Provider within that service. Once the Provider created, set the API URL the Provider is registered against and keep the Provider API key and external ID handy as they will be required to send messages.
See the configuration section for your framework of choice. (coming soon...)
CacheConfigFinder
This package will automatically send API requests to the EonX Notification service to fetch the configuration for your ApiKey and Provider. This will ensure your application has the latest configuration, however, this configuration can easily be cached as it doesn't change often.
This is why this package provides you with a EonX\EasyNotification\Config\CacheConfigFinder to decorate the default
config finder service and cache the found config.
The EonX\EasyNotification\Config\CacheConfigFinder implementation relies on the Symfony Cache Component so you
will need to make sure it is installed in your project.
See how to override the config caching within your framework of choice section.
Usage
Once configured this package will fetch the required configuration from the EonX Notification service and register
a EonX\EasyNotification\Client\NotificationClientInterface service into your DI container. You can then inject
this client into your own classes and send notifications:
// src/Listener/UserCreatedListener.php namespace App\Listener; use App\Entity\User; use EonX\EasyNotification\Client\NotificationClientInterface; use EonX\EasyNotification\Message\RealTimeMessage; use EonX\EasyNotification\Provider\ConfigProviderInterface; final class UserCreatedListener { /** * @var \EonX\EasyNotification\Provider\ConfigProviderInterface */ private $configFinder; /** * @var \EonX\EasyNotification\Client\NotificationClientInterface */ private $client; public function __construct(ConfigProviderInterface $configFinder, NotificationClientInterface $client) { $this->configFinder = $configFinder; $this->client = $client; } public function created(User $user): void { /** * In real use case, those values should come from configuration. * * For multi-tenancies application, it is a best practice to store those values against each tenancy. */ $config = $this->configFinder->provide('my-api-key', 'my-provider-external-id'); /** * Topics are "channels" to send notifications to. * Every clients subscribing to any of the topics will then receive the notification. */ $topics = [$user->getExternalId()]; // Good practice is to have 1 topic per user /** * Body is the notification contents each client will receive. * Its structure is completely up to the application but should negotiated with subscribers. */ $body = [ 'title' => 'Welcome!', 'body' => \sprintf('We are to have you onboard %s', $user->getUsername()), ]; $this->client ->withConfig($config) // Set config for next send ->send(RealTimeMessage::create($body, $topics)); // Send real time message } }
eonx-com/easy-notification 适用场景与选型建议
eonx-com/easy-notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.11M 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 eonx-com/easy-notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eonx-com/easy-notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.11M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-12