删除未订阅的订阅

发布于 2025-01-21 16:02:20 字数 444 浏览 1 评论 0 原文

  • Laravel6
  • Lighthouse-PHP5

我正在使用Lighthouse-PHP进行GraphQL订阅,并且我收到了Pusher的消息。

因此,我有订阅的问题取消订阅。

服务器端=> pusher =>前侧

文档此部分意味着只停止 pusher =>前侧。 如果我不删除redis,仍然可以使用服务器端并将消息推向推动器,对吗?

  unsubscribeFromChannel(subscriptionChannel) {
    this.pusher.unsubscribe(subscriptionChannel);
  }

我想停止服务器sine =>推动器也。 我有什么选择?

谢谢

  • Laravel6
  • lighthouse-php5

I'm using lighthouse-php for GraphQL Subscription and I receive the message from pusher.

So I have the question of Subscription unsubscribe.

server side => pusher => front side

Documantation this part means just stop pusher => front side.
If I don't remove the redis, still server side working and push message to pusher, right?

  unsubscribeFromChannel(subscriptionChannel) {
    this.pusher.unsubscribe(subscriptionChannel);
  }

I want to stop server side => pusher too.
What options I have?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残月升风 2025-01-28 16:02:20

这是在灯塔文档中记录的,此处的直接链接:

但是,这里的一些片段以防万一。

订阅不会自行过期。除非您删除订阅,否则它将在客户断开连接后继续广播事件。

自动过期订阅的最简单方法是使用env lighthouse_subscription_storage_ttl以秒为单位设置到期时间(例如,lighthouse_subscription_storage_ttl = 3600在一小时内到期)。

)。

)。

)。

因此,设置此 .env 变量是一种过期订阅的好方法,这些订阅会自动留在后面,如果您每小时有很多长期运行的订阅,则设置足够大的时间。

但是,由于您使用的是Pusher,因此有一种更快的方法来清理订阅:

如果您使用的是推动器驱动程序,则可以使用“存在” Webhook来减轻此问题。当推动器频道被放弃(即未取消订阅)时,它将触发Webhook,该网络将灯塔指示删除订阅。

此Webhook(频道存在Webhook作为Pusher称为它们)将删除已腾空的通道(没有剩余的订户)的订阅,这将发生在用户断开连接将订阅保持在Redis中的几秒钟。


这么长的故事简短,为订阅设置了TTL作为后备,并为您的应用程序配置了Pusher Webhook。这将使订阅保持最新状态并防止不需要的工作。

This is documented in the Lighthouse documentation, a direct link here: https://lighthouse-php.com/5/subscriptions/getting-started.html#expiring-subscriptions.

But also some snippets here just in case it helps.

Subscriptions do not expire by themselves. Unless you delete a subscription, it will continue to broadcast events after the client has disconnected.

The easiest way to expire subscriptions automatically is to use the env LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL to set an expiration time in seconds (e.g. LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL=3600 to expire in one hour).

So setting this .env variable is a great way to expire subscriptions that are left behind automatically, do set this timeout large enough, if you have a lot of long running subscriptions an hour might not be enough.

But since you are using Pusher there is a faster way to cleanup the subscriptions:

If you are using the Pusher driver, you can use a Presence webhook to mitigate this problem. When a Pusher channel is abandoned (ie. unsubscribed), it will trigger the webhook, which will instruct Lighthouse to delete the subscription.

This webhook (channel existence webhook as Pusher calls them) will remove subscriptions for channels that are vacated (no subscribers left) this will happen a few seconds after the user disconnects keeping the subscriptions in Redis up-to-date.


So long story short, setup a TTL for the subscriptions as a fallback and configure the Pusher webhook for your app. This will keep the subscriptions stored up-to-date and prevent unneeded work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文