fotografde/notification-library
Composer 安装命令:
composer require fotografde/notification-library
包简介
A simple library to push events events to the queue to be handled by the Notification Service
README 文档
README
Notification Library
A simple library to push data to be handled by the Notification Service
Setup
-
add to your (project folder)/composer.json
"require": { ... "fotografde/notification-library": "*" } -
run
(project folder)> composer update -
modify the configuration file, if necessary
(project folder)> cp vendor/GetPhoto/notification-library/config/notification.php.default vendor/GetPhoto/notification-library/config/notification.php OR (project folder)> cp src/vendors/GetPhoto/notification-library/config/notification.php.default src/vendors/GetPhoto/notification-library/config/notification.php**OR (for local configuration) **
(project folder)> cp config/notification.php.default config/notification.php -
and configure it
'events_table' => 'EventQueue', 'region' => '...', 'endpoint' => '...', 'credential_key' => '...', 'credential_secret' => '...', 'notification_service_url' => '...', 'method_add_trigger' => 'api/trigger',
Events
Usage
-
Import the Notification class
use GetPhoto\Notification;
-
Pass the data to the method to push events
(new Notification)->pushEvent($data);
-
Examples
-
User Login
$data = [ 'eventTypeId' => 'User.Login', 'dateTime' => '20170117 232900', 'userId' => '1', 'photographerId' => '1', ]; (new Notification)->pushEvent($data);
-
New Contactsheet
$data = [ 'eventTypeId' => 'Contactsheet.Created', 'dateTime' => '20170115 080005', 'userId' => '5', 'photographerId' => '2', 'contactsheetId' => 'a0shfd0a9shf9', ]; (new Notification)->pushEvent($data);
-
Triggers
Usage
-
Import the Trigger class
use GetPhoto\Trigger;
-
Instantiate a new object, add the options and save
//Trigger ID => Unique name for your trigger //Trigger type => EventBased, Scheduled, TimeBased or Manual //Trigger action => Action to be executed $trigger = new Trigger('trigger id', 'trigger description', 'trigger type', 'trigger action'); //optional methods $trigger->addSubscriptionKey('value'); $trigger->addDelay('value'); $trigger->addWhen('value'); //auxiliar methods $trigger->createActionParameterConstant('constant', 'value'); $trigger->createActionParameterVariable('variable', 'value'); $trigger->createActionParameterMethod('variable', 'method', ['arguments', ...]); //optional methods that can be used multiple times $trigger->addActionParameter($parameter); $trigger->addParameter(['data key' => 'data value', ...]); $trigger->save();
Samples
Manual Trigger
Triggers that are executed via api request
-
Return a json with all login from an user
Problem: We need a trigger to feed the user's config page with all of his logins. The config page will make an api request whenever the user request the login data.
Solution: We have the method returnEvents which filter events based on given arguments. In this case, we want to filter by EventTypeId and UserId. We can obtain the UserId from the subscription, so it is a variable. Since we already know the EventTypeId, we define a constant.
$trigger = new Trigger('UserLogins.v1', 'Shows all logins from an user', 'Manual', 'method::returnJson'); $trigger->addSubscriptionKey('UserId'); $userId = $trigger->createVariable('userId', 'userId'); $eventTypeId = $trigger->createConstant('eventTypeId', 'User.Login'); $eventsMethod = $trigger->createMethod('returnJson', [$userId, $eventTypeId]); $events = $trigger->createVariable('events', $eventsMethod); $trigger->addActionParameter($events); $trigger->save();
Result:
- Trigger ID: UserLogins.v1
- Trigger Description: Shows all logins from an user
- Type: Manual
- Subscription Key: UserId
- Action: method::returnJson
- Action Parameters: events::{{returnEvents||userId::[[userId]]||eventTypeId::User.Login}}
Usage:
http://notification-service-url/queryEvents/UserLogins.v1/subscriber-id
fotografde/notification-library 适用场景与选型建议
fotografde/notification-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「events」 「notification service」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fotografde/notification-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fotografde/notification-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fotografde/notification-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Библиотека для реализаций паттерна Pub/Sub
Wireless Cross-Component Communication
A fast and intuitive dependency injection container.
A powerful event calendar Tool for Laravel's Nova 5.
Apple Push Notification & Feedback Provider
统计信息
- 总下载量: 39.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-05-24