Retrieving packet size


I’m writing a Publish Inbound Interceptor that will retrieve the size of a packet sent by a client. I was looking at the methods of PublishPacket but couldn’t find one that returns the packet size. Please can anyone let me know if I missed anything?


Hello SpringD,

the encoded size of the message sent by the client is not exposed to the PublishPacket object.

If you are only interested in the payload you can check the length of the payloads bytes like this

if(publishPacket.getPayload().isPresent()) {
     System.out.println("Payload size: " + publishPacket.getPayload().get().rewind().remaining());

Hi FloLi,

Thanks! That’s very helpful.