Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot with websocket and postman

I have created test project according to tutorial

@Configuration
@EnableWebSocketMessageBroker
public class WSConfig implements WebSocketMessageBrokerConfigurer {

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

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

@Controller
public class WSController {

    @MessageMapping("/chat")
    @SendTo("/topic/messages")
    public String send(String message) throws Exception {
        return "test";
    }
}

I am struggling to connect with postman, I tried different urls:

  • ws://localhost:8080

  • ws://localhost:8080/app

  • ws://localhost:8080/app/chat

each time I click connect button, I get 404 as a response What am I doing wrong? (I am new to websocket)

like image 685
rsobies Avatar asked Jun 24 '26 03:06

rsobies


1 Answers

I was able to connect to the ws://localhost:8080/chat endpoint after following instructions at https://blog.postman.com/postman-supports-websocket-apis/

enter image description here

Note: I also looked at https://spring.io/guides/gs/messaging-stomp-websocket/ for more information on setting up a SpringBoot WebSocket project.

like image 54
Asif A Fasih Avatar answered Jun 26 '26 20:06

Asif A Fasih



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!