簡體   English   中英

Spring websocket STOMP從eventHandler取消訂閱

[英]Spring websocket STOMP Unsubscribe from eventHandler

我有一個接受訂閱請求的 Spring Websocket Stomp 應用程序。

在應用程序中,我有一個 SUBSCRIBE 處理程序,即,

 @Component
 public class SubscribeStompEventHandler implements ApplicationListener<SessionSubscribeEvent> {

    @Override
    public void onApplicationEvent(SessionSubscribeEvent event) {}
 }

我用來驗證訂閱。

如果訂閱無效,例如,當前用戶看不到該訂閱,我希望 Broker(我使用 SimpleMessagingBroker)“忘記”該訂閱,或者最好不要注冊它。

我的問題是:

  • 如果我將訂閱請求的處理轉移到傳入消息攔截器並停止消息傳播,我可以讓 Broker 不注冊訂閱嗎?

  • 此事件處理程序還可以使用什么來取消訂閱?

您需要創建ChannelInterceptor實現。 只需擴展ChannelInterceptorAdapter並覆蓋preSend(Message<?> message, MessageChannel channel) 在這里,您可以訪問帶有會話信息的標頭以進行驗證。 你還需要注冊你的攔截器

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.configureBrokerChannel().interceptors(new YourInterceptor())
    registry.enableSimpleBroker("/queue/", "/topic/");
    registry.setApplicationDestinationPrefixes("/app");
}

此處的更多信息如何使用 Spring-websocket 根據用戶權限拒絕主題訂閱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM