如何在Spring WebSockets中找到所有订阅主题的用户 [英] How to find all users subscribed to a topic in spring websockets

查看:90
本文介绍了如何在Spring WebSockets中找到所有订阅主题的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Spring Websockets制作聊天应用程序时,了解谁都订阅了给定主题很有用.例如客户端中显示的状态数据.

When making something like a chat application using Spring Websockets, it is useful to know who all is subscribed to any given topic. For, e.g. presence data displayed in the clients.

我知道我可以实现ApplicationListener并保留我自己的已连接用户"列表,但是似乎该库必须已经在进行这项工作.

I know that I can implement ApplicationListener and keep my own list of "connected users", but it seems like the library must already be doing this work.

直接从库中获取活动订阅信息的推荐方法是什么(而无需在内存或数据库中维护我自己的列表).

What's the recommended way to get active subscription info from the library directly (and without maintaining my own list in memory or db).

推荐答案

您是对的,您可以使用

You're right, you could use ApplicationContext events, but unfortunately those events deal with user sessions events and broker events - so you won't be notified when a user subscribes to a particular topic.

使用

You could do that when using the SimpleBrokerMessageHandler, by getting the SubscriptionRegistry. But again, the SimpleMessageBroker is not for production use.

如果您使用RabbitMQ,则可以从其REST API获取该信息.

If you're using RabbitMQ, you can get that information from its REST API.

问题是,这是非常特定于代理实现的,因此我想知道这样的功能在Spring Framework中是否有意义.您可以打开 JIRA问题来开始讨论吗?

The thing is, this is very specific to the broker implementation, so I'm wondering if a feature like that makes sense in Spring Framework. Could you open a JIRA issue to start the discussion?

这篇关于如何在Spring WebSockets中找到所有订阅主题的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆