Search code examples
spring-websocketjava-websocket

Websocket client to consume continuous stream of messages from server


I have a websocket server with url "wss://api.client.com/subscribe/" which gives a continuous stream of json messages (about 1200 bytes per message).

I have created a websocket client as mentioned in "https://stackoverflow.com/a/26454417/6700081"

The client is consuming the messages but after sometime I get the error,

closing websocketCloseReason: code [1009], reason [The decoded text message was too big for the output buffer and the endpoint does not support partial messages]

How do I clear the buffer after I receive a message? Or is there a way to reconnect to server as soon as connection is closed?

I am consuming the message as soon as it is returned by the server and printing it in the console. I dont want the messages to be stored in buffer because no matter how much I increase the buffer size, it is filled up by the server since it is a continuous stream of messages


Solution

  • Use io netty websocket client https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/websocketx/client