承接 mwangaben/lighthouse-redis-broadcaster 相关项目开发

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

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

mwangaben/lighthouse-redis-broadcaster

Composer 安装命令:

composer require mwangaben/lighthouse-redis-broadcaster

包简介

A lighthouse-php redis broadcaster to be used with laravel-echo-server.

README 文档

README

Lighthouse already supports pusher, but does not deliver its own redis based solution. This package enables graphql subscriptions using presence channels of the laravel-echo-server.

For a client solution, check out the Apollo Lighthouse Subscription Link.

Installation

I assume that you already have Lighthouse and laravel-echo-server installed. If not, please check out their installation steps before continuing.

Install the package with composer:

composer require thekonz/lighthouse-redis-broadcaster

Add the service provider after the Lighthouse subscription service provider in the config/app.php:

        /*
         * Package Service Providers...
         */
        \Nuwave\Lighthouse\Subscriptions\SubscriptionServiceProvider::class,
        \thekonz\LighthouseRedisBroadcaster\SubscriptionServiceProvider::class,

Add this to your .env:

LIGHTHOUSE_BROADCASTER=redis
REDIS_PREFIX=

If you do not set the REDIS_PREFIX to empty, it will default to <app name>_database_ (by default: laravel_database_) and all redis channels will be prefixed with it.

Setting up automatic removal of subscription channels

Lighthouse by default does not remove vacated channels. In order to prevent redis from running low on memory all the time, you need to configure the laravel-echo-server to publish updates about its presence channels and run a subscriber that removes vacated channels from redis.

Enable presence channel updates in your laravel-echo-server.json by setting publishPresence to true:

  "databaseConfig": {
    ...
    "publishPresence": true
  }

Run the subscription command to remove vacated channels:

php artisan lighthouse:subscribe

Usage

If you are using Apollo, you should use the Apollo Lighthouse Subscription Link.

Create a subscription as described in the Lighthouse docs. For the purpose of demonstration, I assume the subscription is postUpdated like in the docs.

Now query the api:

subscription test {
  postUpdated {
    id
    title
  }
}

The response will be:

{
  "data": {
    "postUpdated": null
  },
  "extensions": {
    "lighthouse_subscriptions": {
      "version": 1,
      "channels": {
        "test": "private-lighthouse-9RrjQE84nqaxXt58ZsgREPaI9AxGjAv4-1588101712"
      }
    }
  }
}

Now you may use laravel echo to monitor the subscription as a presence channel:

Echo.join(
  "private-lighthouse-9RrjQE84nqaxXt58ZsgREPaI9AxGjAv4-1588101712"
).listen(".lighthouse.subscription", ({ channel, data }) => {
  console.log(channel); // private-lighthouse-9RrjQE84nqaxXt58ZsgREPaI9AxGjAv4-1588101712
  console.log(data); // { postUpdated: { id: 1, title: "New title" } }
});

Contributing and issues

Feel free to contribute to this package using the issue system and pull requests on the develop branch.

Automated unit tests must be added or changed to cover your changes or reproduce bugs.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固