1

So, i was trying to replicate sockJs code from an excellent example by Rossen Stoyanchev here: https://github.com/rstoyanchev/spring-websocket-portfolio/blob/master/src/test/java/org/springframework/samples/portfolio/web/load/StompWebSocketLoadTestClient.java

However, i've encountered an issue in that it won't connect to Stomp endpoint. Execution freezes on stompClient.connect(), no further debug messages are shown, not even from the Handler.

Here's my code:

public void waitForGreet() throws Exception {

    String stompUrl = "ws://127.0.0.1:61613/stomp";

    StandardWebSocketClient webSocketClient = new StandardWebSocketClient();

    HttpClient jettyHttpClient = new HttpClient();
    jettyHttpClient.setMaxConnectionsPerDestination(1000);
    jettyHttpClient.setExecutor(new QueuedThreadPool(1000));
    jettyHttpClient.start();

    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(webSocketClient));
    transports.add(new JettyXhrTransport(jettyHttpClient));

    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.afterPropertiesSet();

    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
    //WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new StringMessageConverter(Charset.defaultCharset()));
    stompClient.setDefaultHeartbeat(new long[]{0, 0});
    stompClient.setTaskScheduler(taskScheduler);

    stompClient.connect(stompUrl, handler, "localhost", 61613);
}

If i use WebSocketStompClient it all works fine.

The issue can be reproduced with ActiveMQ, so i assume it's not Artemis-specific. I run this app using Spring Boot and i haven't specifically configured anything, it worked just fine with WebSocketStompClient.

If anyone has encountered a similar problem, i would greatly appreciate any insight or suggestion on how i can fix this. Am i missing some additional broker/spring-app configuration here?

0 Answers0