bridit/laravel-sns 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bridit/laravel-sns

Composer 安装命令:

composer require bridit/laravel-sns

包简介

Laravel Broadcasting SNS

README 文档

README

Laravel SNS allow you to broadcast and listen to SNS events. It implements a driver on BroadcastManager to make the use of SNS as easy as Laravel Events. It also implements a controller, using rennokki/laravel-sns-events package, that is made to properly listen to SNS HTTP(s) webhooks and trigger events on which you can listen to.

If you are not familiar with Laravel Events & Listeners, make sure you check the documentation section on laravel.com because this package will need you to understand this concept.

Make sure to also check rennokki/laravel-sns-events documentation.

Install

$ composer require bridit/laravel-sns

Configuration

You will need an AWS account and make sure you have it properly configured on Laravel, following the steps of official documentation.

Then you need to register a connection for SNS on broadcasting.php, you can do this adding code above on connections section of broadcasting.php:

...

'sns' => [
  'driver' => 'sns',
  'route' => '/aws/sns',
  'key' => env('AWS_ACCESS_KEY_ID'), // optional
  'secret' => env('AWS_SECRET_ACCESS_KEY'), // optional
  'region' => env('SNS_REGION'), // optional
  'arn_prefix' => 'arn:aws:sns:' .
    env('AWS_SNS_REGION', env('AWS_REGION', 'us-east-1')) . ':' . env('AWS_ACCOUNT_ID'),
],

We made use of env variables to build arn_prefix, but you can also specify a simple string. You can find your arn on AWS platform, on any topic you own.

This package auto register the necessary routes for you, on web middleware, using 'route' attribute of broadcasting.php. You don't need to do it by yourself.

SNS sends data through POST, so you will need to whitelist your route in your VerifyCsrfToken.php:

protected $except = [
  ...
  '/aws/sns', // Or other route that you set on broadcasting.php
];

If you want this to be your default broadcasting driver set it on your .env:

BROADCAST_DRIVER=sns

Now you are ready to go. Just create a topic and set up a subscription for HTTP(s) protocol that will point out to the route you just registered. Click the confirmation button from the AWS Dashboard. In a short while, if you implemented the route well, you'll be seeing that your endpoint is registered.

Usage

To send SNS events just use default Laravel dispatcher, like:

event(new OrderShipped($order));

The package comes with two event classes:

  • Rennokki\LaravelSnsEvents\Events\SnsNotification - triggered on each SNS message
  • Rennokki\LaravelSnsEvents\Events\SnsSubscriptionConfirmation - triggered when the subscription is confirmed

To process the events, you should add the events in your app/Providers/EventServiceProvider.php:

use Rennokki\LaravelSnsEvents\Events\SnsNotification;
use Rennokki\LaravelSnsEvents\Events\SnsSubscriptionConfirmation;

...

protected $listen = [
    ...
    SnsNotification::class => [
        // add your listeners here for SNS events
    ],
    SnsSubscriptionConfirmation::class => [
        // add your listeners here in case you want to listen to subscription confirmation
    ],
]

You will be able to access the SNS message from your listeners like this:

class MyListener
{
    ...

    public function handle($event)
    {
        // $event->payload is an array
    }
}

License

The MIT License (MIT).

bridit/laravel-sns 适用场景与选型建议

bridit/laravel-sns 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.69k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 bridit/laravel-sns 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-18