0
votes

We are using Spring Boot version 1.2.8.RELEASE which has a managed dependency of org.projectoreactor.* with Reactor version 1.1.6.RELEASE.

The issue I am facing is inside my custom Codec (reactor.io.encoding.Codec) the given Buffer (reactor.io.Buffer) is capped at 1024 bytes but my message exceeds that limit. When I attempt to decode the messages it is not the full message (only a partial) and my decoding fails as it expects the full message.

Question One: How do I increase Buffer bytes (reactor.io.Buffer) so my apply function works correctly? Simple example below:

public class StringDecoder implements Function<Buffer, String> {

    // Buffer is limited to 1024 but the message the client sent
    // was 2k
    @Override
    public String apply(Buffer bytes) {
        return bytes.toString();
    }
}

Question Two: How do I make the apply function (above) chunked? This means that when Netty's buffer reaches its limit, my apply function can create its own buffer (and manage the buffer) and eventually I can decode the message and Reactory/Netty can pass it to a Consumer.

Note: In my "main" method the following is used to setup the environment. The Netty Server is running under Windows and the client is on linux. Is this related to Windows implementation of TCP?

// NOTES: ServerSocketOptions sets the max buffer for send and receive to 
// something much larger than 1024. Verified with debugger
TcpServerSpec<String, String> spec = new TcpServerSpec<String, String>(NettyTcpServer.class);
spec.env(env);
spec.listen(port);
spec.dispatcher("sync");
spec.codec(new AgentCodec());
spec.consume(connectionHandler(handler));

TcpServer<String, String> tcp = spec.get();
tcp.start().await();
1

1 Answers

0
votes

Okay, after debugging the code and I figured out what the issue is -- BTW this is not found in any documentation I found on the Reactor project (tisk tisk).

The apply function will keep getting called with more of the message. So if the message is 2K, apply will get called twice. First time with 1K, then second time with 2K.

NOTE: If you do not advanced the buffer position, it will append to the buffer. If you do advanced the buffer position, it will be removed when apply gets called again.