onkami
onkami

Reputation: 9411

Spring boot application with websocket client only

I am writing a Spring Boot app that uses spring websocket client with jetty, but I do not need any server functions. How can I switch off Jetty server part, so it won't get activated at startup and does not listen on a port?

Upvotes: 1

Views: 4269

Answers (2)

amelongo
amelongo

Reputation: 123

I struggle to find a solution for this as all the examples online use a combination of server and client. In the event you only need to connect to a remote websocket server using a webflux server, the code needed to do this is only:

    WebSocketClient client = new ReactorNettyWebSocketClient();

URI url = new URI("ws://remote:8080/path");
client.execute(url, session ->
        session.receive()
                .doOnNext(/*logic to handle message*/)
                .then()).subscribe();

You can find the documentation here("Client" Section: https://docs.spring.io/spring-framework/reference/web/webflux-websocket.html

Upvotes: 0

I'm sorry for the delay in having your question answered.

I also had difficulty finding the answer, so I created a repository in Github with a simple solution, its here:

https://github.com/GleidsonSilva/springboot-ws-client

I hope it is still useful to someone! :)

Cheers!

Upvotes: 4

Related Questions