简体   繁体   中英

How to get the Jgroups Message object content as string

I'm using jgroups for cluster node communication. I'm sending messages using channel, but unable to get the received message content. Used msg.getBuffer() and msg.getRawBuffer() methods, but after converting into string getting SOH SOH in the outpout. I just want only the message content not the 'src' or 'dest' hosts. How to get that from Message object?

If you use a string as payload, I suggest either

  • Set the contents using msg.setObject("hello world") and msg.getObject() , which returns the string "hello world"

OR

  • Set the contents using msg.setBuffer("hello world".getBytes()) and new String(msg.getRawBuffer(), msg.getOffset(), msg.getLength()) .

In the first case, you use a helper method of JGroups to set and retrieve the object, in the latter case you do the (de-)serialization yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM