【问题标题】:Spring websocket Client to Client communicationSpring websocket客户端到客户端通信
【发布时间】:2023-08-06 06:12:01
【问题描述】:

我有一个要求,我的 Websocket 会话应该能够相互通信。我正在创建一个请求响应模型,我的客户端 A 将在我有多个订阅代理(Ag1 和 Ag2)的队列上发送请求.我希望我的请求会在这两个订阅者之间循环。不幸的是,该事件被广播给两个代理,而不是一对一的通信。

我的 Spring 配置

@Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.setApplicationDestinationPrefixes("/app");
        config.enableSimpleBroker("/queue", "/topic");
    }

客户端 JS 代码

requestResponse = new RequestResponse({
    outgoingChannel : "/queue/clients",
    incomingChannel : "/topic/broadcast/clients",
    callbackFn : widget3eventHandler
},session);

代理订阅者代码

requestResponse = new RequestResponse({
    outgoingChannel : "/topic/broadcast/clients",
    incomingChannel : "/queue/clients",
    callbackFn : widget3eventHandler,
    processAll : true
},session);

这是 SIMP Broker 中的错误还是我做错了什么。

【问题讨论】:

    标签: spring stomp spring-websocket


    【解决方案1】:

    想了解如何实现客户端通信,可以查看this sample chat application

    【讨论】:

    • 谢谢布赖恩..我会看看。
    最近更新 更多