javascript - Multiple STOMP subscriptions from JS to Spring in one request - Stack Overflow

The goal is to make multy-room chat using web interface and Spring framework. Lookes like STOMP over So

The goal is to make multy-room chat using web interface and Spring framework. Lookes like STOMP over SockJS is the best bo for such project. STOMP's destination based subscription resolves all broadcasting issues. But if user uses 100 (for example) chats at once I need to send 100 subscription requests from web client each time he logs in.

So I'm looking for alternative one-request solution. Let me to consolidate questions:

1) Is there a way to make one client-side STOMP request for several subscriptions at once? If it is possible to make such request using other JS library - then I'll be glad to try it.

2) Is there a way to initiate subscriptions from Spring backend side? It would be great to register several destination message queries for one client on server side - I can use special request for that or do that during logging in.

3) Any other suggestions about this issue? Again: I'm glad to try other trendy tech as a last resort.

The code beloiw is the most simple echo service. I'm just testing this protocol and technology.

Basic client code:

window.onload = function () {
    window.s = new SockJS("http://localhost:8080/portfolio");
    window.s.onopen = function () {
        window.stompClient = Stomp.over(window.s);

        stompClient.connect('admin', 'admin', function(frame) {
            console.log('Connected: ', frame);
            stompClient.subscribe('/topic/echo', function(messageOutput) {
                console.log(messageOutput.body);
            })}, function(e){console.log("Fail My: ", e);})();
    };
};

STOMP config:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/portfolio").setAllowedOrigins("*").withSockJS()
        .setClientLibraryUrl( "/[email protected]/dist/sockjs.min.js" );
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {

        registry.enableSimpleBroker("/topic/");
        registry.setApplicationDestinationPrefixes("/app");
    }
}

STOMP controller:

@Controller
public class GreetingController {

    @MessageMapping("/greetings")
    @SendTo("/topic/echo")
    public String handleMessage(@Payload String greeting) {
        System.out.println("[received]:" + greeting);
        return "[echo]: " + greeting;
    }
}

The goal is to make multy-room chat using web interface and Spring framework. Lookes like STOMP over SockJS is the best bo for such project. STOMP's destination based subscription resolves all broadcasting issues. But if user uses 100 (for example) chats at once I need to send 100 subscription requests from web client each time he logs in.

So I'm looking for alternative one-request solution. Let me to consolidate questions:

1) Is there a way to make one client-side STOMP request for several subscriptions at once? If it is possible to make such request using other JS library - then I'll be glad to try it.

2) Is there a way to initiate subscriptions from Spring backend side? It would be great to register several destination message queries for one client on server side - I can use special request for that or do that during logging in.

3) Any other suggestions about this issue? Again: I'm glad to try other trendy tech as a last resort.

The code beloiw is the most simple echo service. I'm just testing this protocol and technology.

Basic client code:

window.onload = function () {
    window.s = new SockJS("http://localhost:8080/portfolio");
    window.s.onopen = function () {
        window.stompClient = Stomp.over(window.s);

        stompClient.connect('admin', 'admin', function(frame) {
            console.log('Connected: ', frame);
            stompClient.subscribe('/topic/echo', function(messageOutput) {
                console.log(messageOutput.body);
            })}, function(e){console.log("Fail My: ", e);})();
    };
};

STOMP config:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/portfolio").setAllowedOrigins("*").withSockJS()
        .setClientLibraryUrl( "https://cdn.jsdelivr/npm/[email protected]/dist/sockjs.min.js" );
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {

        registry.enableSimpleBroker("/topic/");
        registry.setApplicationDestinationPrefixes("/app");
    }
}

STOMP controller:

@Controller
public class GreetingController {

    @MessageMapping("/greetings")
    @SendTo("/topic/echo")
    public String handleMessage(@Payload String greeting) {
        System.out.println("[received]:" + greeting);
        return "[echo]: " + greeting;
    }
}
Share Improve this question edited Jul 15, 2019 at 6:31 Lex asked Jul 15, 2019 at 6:21 LexLex 5241 gold badge5 silver badges15 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

The STOMP specification indicates that 1 SUBSCRIBE frame correlates to 1 subscription. In other words, there's no way to get multiple subscriptions for a single SUBSCRIBE frame.

It's possible (although unlikely in my opinion) that a library/API would wrap the ability to send multiple SUBSCRIBE frames in a single call, but that would just a convenience method and wouldn't actually yield any kind of performance benefit at the protocol level.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744747290a4591378.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信