What is the right way to get the size of a message in solace?

Options
esterv
esterv Member Posts: 1

What is the right way to get the size of a message in solace using Java API?

I have this handler and want to get the size of msg:

public void onData(MapMessage msg) {

}


I tried this:

java.nio.ByteBuffer buffer = msg.getAttachmentByteBuffer();

int size_rem = buffer.remaining();

And also since SDTMap does not seem to be serializable, I copied the values to a java hashmap, serialized it and then got the size of that byteArray.

My goal is to figure out the payload size of the application message transferred over the wire.

Answers

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 541 admin
    Options

    Hi @esterv. Welcome to the Community!

    Unfortunately, there's no public way to get the message size on-the-wire out of the Java API (either JCSMP or the new Java API). Trust me, I've asked a bunch of times, asked the API developers, no luck. Not willing to expose it. Which annoys me b/c I've written some apps where this would be really useful. Sorry. I can share some code with you where I guess at the size of the message if you want... it's not too bad, but it's not perfect.

    The broker obviously knows exactly how many bytes and messages are going to particular apps. Are you building a monitoring app or something?

    Also, if this is a new project, we seem to be trying to discourage use the SDTMap and Stream b/c they are proprietary encodings. So if interfacing with other apps using our open standards (MQTT, AMQP), they won't be able to decode. I've been using just plain JSON now instead of SDTMaps.

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    Options

    Hi @esterv,

    I just want to follow up on @Aaron's post and say another option besides JSON would be to use a 3rd party data serialization library like Google Protocol Buffers (Protobuf) to serialize your payload before putting it into the solace message. If you go that route then you can usually use that library to get the size + it helps with the issue @Aaron mentioned about proprietary encodings.

    @TomF wrote a blog which covers how using a 3rd party data serialization library with Solace would work: https://solace.com/blog/buffing-messages-3rd-party-data-serialization/