🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

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

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: 644 admin

    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: 963 admin

    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/

This Week's Leaders