定制 fotografde/notification-library 二次开发

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

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

fotografde/notification-library

最新稳定版本:1.1.1

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

Build Status

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-05-24