我有一个接受SUBSCRIBE请求的Spring Websocket Stomp应用程序。
在应用程序中,我有一个SUBSCRIBE的处理程序,即,
@Component
public class SubscribeStompEventHandler implements ApplicationListener<SessionSubscribeEvent> {
@Override
public void onApplicationEvent(SessionSubscribeEvent event) {}
}
我用来验证订阅。
如果订阅无效,例如,当前用户看不到该订阅,我希望Broker(我使用SimpleMessagingBroker)“忘记”该订阅,或者最好不要注册它。
我的问题是:
>
如果我将订阅请求的处理移至传入消息拦截器并停止消息传播,我可以让Broker不注册订阅吗?
此事件处理程序还可以使用什么来取消订阅?
您需要创建您的ChannelInterceptor
实现。只需扩展ChannelInterceptorAdapter
并覆盖pre发送(消息
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.configureBrokerChannel().interceptors(new YourInterceptor())
registry.enableSimpleBroker("/queue/", "/topic/");
registry.setApplicationDestinationPrefixes("/app");
}
此处的更多信息如何使用Spring-websocket根据用户权限拒绝主题订阅