承接 pbmengine/pbm-stream-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pbmengine/pbm-stream-sdk

Composer 安装命令:

composer require pbmengine/pbm-stream-sdk

包简介

SDK for using PBM Stream API

README 文档

README

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require pbmengine/pbm-stream-sdk

Usage

php artisan vendor:publish

Update the config file with url, project id and access key.

# in ./config/pbm-stream.php
return [
    'url' => env('PBM_STREAM_URL', ''),
    'project' => env('PBM_STREAM_PROJECT', ''),
    'access_key' => env('PBM_STREAM_ACCESS_KEY', '')
];

Now you can use the stream api.

# via helper
stream('logins')->record(['user' => 1, 'age' => 30]);

# via Facade
\Pbmengine\Stream\Facades\Stream::collection('logins')->record(['user' => 1, 'age' => 30]);

Available methods

# record event
stream('logins')->record(['user' => 1, 'age' => 30]);

# update event
stream('logins')->updateEvent('<event id>', ['age' => 30]);

# update several events with condition
# field is the condition field with value
# e.g. field is userId and value is 300
# stream('logins')->updateEvents('userId', 300, ['age' => 30]);
# means: update all events where userId is 300 and set age to 30
stream('logins')->updateEvents('field', 'value', ['age' => 30]);

# update events where you have several = conditions
stream('logins')->updateEventsWithConditions([
    'event' => 'items.purchased',
    'customerId' => 5
], [
    'age' => 30,
    'itemsPurchased' => true
]);

# delete event
stream('logins')->deleteEvent('<event id>');

# get project information
stream()->project();

# get project collections
stream()->collections();

# get collection informations
stream('logins')->collection();

# validate collection event
stream('logins')->validateEvent(['user' => 2, 'age' => 10]);

# test event to check if it's a valid event for any collection
# you do not need any collection for this request
stream()->testEvent(['user' => 2, 'age' => 10]);

# create collection index
# timestamp and _id are automatically indexed
stream('logins')->createIndex('<field>');

# drop collection index
stream('logins')->dropIndex('<field>');

# add new property key to collection
# - field is the name of the property
# - defaultValue is the default value for existing documents
# - type is the type of the property (string, bool, num, array)
stream('logins')->addPropertyKey(<field>, <defaultValue>, <type>);

# delete property key from collection
stream('logins')->deletePropertyKey(<field>);

# rename property key in collection
stream('logins')->renamePropertyKey(<oldField>, <newField>);

# query options
$response = stream('logins')
    ->query()
    ->select(['_id', 'event', 'itemPrice'])
    ->where('a', '=', 2)
    ->whereIn('<column>', ['array', '...']) 
    ->orWhere('b', '>', 6)
    ->timeFrame('<start date iso 8601>', '<end date iso 8601>')
    ->timeFrame(TimeFrame::THIS_DAYS, 5)
    ->timeFrame(TimeFrame::PREVIOUS_DAYS, 6)
    ->groupBy('<column>') // (['field a', 'field b'])
    ->orderBy('<column>', 'asc') // second parameter is optional, default is asc 
    ->orderByDesc('<column>') // order desc
    ->count(); // sum(field) | avg(field) | max(field) | min(field) | countUnique(field) | selectUnique(field)

// get events
$response = stream('pages')
    ->query()
    ->where('event', '=', 'page.viewed')
    ->orWhere('event', '=', 'login.viewed')
    ->take(10)
    ->orderByDesc('timestamp')
    ->get();

// get events with pagination
$response = stream('pages')
    ->query()
    ->where('event', '=', 'page.viewed')
    ->orderByDesc('timestamp')
    ->paginate(10, 1); // per page 10 events on page 1

# complex queries
# for more complex queries use the aggregate function
stream('pages')
    ->query()
    ->aggregate([
        ['$match' => ['event' => 'pageViewed']]
    ]);

Responses

Responses are always Laravel Http Client Responses!

# get() method
$response = stream('pages')->take(1)->get()->json();
{
  "data": [
        {
            "_id": "61b28877a57f17655163cea2",
            "event": "video.started",
            "userId": 107,
            "customerId": 772,
            "hasContract": false,
            "customerAge": 34,
            "hasChildren": false,
            "persona": "mf",
            "timestamp": "2021-12-09T22:51:34.000000Z",
            "clientDevice": "desktop",
            "clientOsName": "Mac",
            "clientOsVersion": "10.15",
            "clientType": "browser",
            "clientName": "Chrome",
            "clientVersion": "95.0",
            "clientIsMobile": false,
            "clientIsBot": false
        }
  ]
}
# paginate() method
$response = stream('pages')->paginate(1)->json();
{
    "data": [
        {
            "_id": "61b28877a57f17655163cea2",
            "event": "video.started",
            "userId": 107,
            "customerId": 772,
            "hasContract": false,
            "customerAge": 34,
            "hasChildren": false,
            "persona": "mf",
            "timestamp": "2021-12-09T22:51:34.000000Z",
            "clientDevice": "desktop",
            "clientOsName": "Mac",
            "clientOsVersion": "10.15",
            "clientType": "browser",
            "clientName": "Chrome",
            "clientVersion": "95.0",
            "clientIsMobile": false,
            "clientIsBot": false
        }
    ],
    "meta": {
        "total": 304,
        "current_page": 1,
        "last_page": 304,
        "per_page": 1,
        "total_pages": 304,
        "count": 1,
        "execution_time": 0.05970406532287598
    }
}
# count(), max(<column>), min(<column>), sum(<column>), avg(<column>) method
$response = stream('pages')->avg('customerAge')->json();
{
  "result": 50.18421052631579
}
# testing events 
$response = stream()->testEvent(['event' => 'test', '2983' => 12, 'test' => null])->json();
{
    "status": "failed",
    "errors": {
        "2983": "2983 must only have alphabetical characters",
        "test": "test must only be a string, boolean or numeric value"
    }
}
# validate events for collection 
$response = stream('purchases')->validateEvent(['event' => 'test'])->json();
{
    "status": "failed",
    "errors": {
        "userId": "num",
        "itemId": "num",
        "itemName": "string",
        "itemQuantity": "num",
        "itemInStock": "bool"
    }
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email stefan@sriehl.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

pbmengine/pbm-stream-sdk 适用场景与选型建议

pbmengine/pbm-stream-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.78k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「pbm」 「pbm-stream-sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 pbmengine/pbm-stream-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

与 pbmengine/pbm-stream-sdk 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-30