admin管理员组文章数量:1394228
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
1 Answer
Reset to default 6The 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.
本文标签: javascriptMultiple STOMP subscriptions from JS to Spring in one requestStack Overflow
版权声明:本文标题:javascript - Multiple STOMP subscriptions from JS to Spring in one request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744747290a2622960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论