简体   繁体   English

如何以字符串形式获取Jgroups Message对象的内容

[英]How to get the Jgroups Message object content as string

I'm using jgroups for cluster node communication. 我正在使用jgroups进行群集节点通信。 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. 使用了msg.getBuffer()msg.getRawBuffer()方法,但是在转换为字符串后,在输出中获得SOH SOH I just want only the message content not the 'src' or 'dest' hosts. 我只希望消息内容而不是“ src”或“ dest”主机。 How to get that from Message object? 如何从Message对象获取该信息?

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" 使用msg.setObject("hello world")msg.getObject()设置内容,这将返回字符串“ hello world”

OR 要么

  • Set the contents using msg.setBuffer("hello world".getBytes()) and new String(msg.getRawBuffer(), msg.getOffset(), msg.getLength()) . 使用msg.setBuffer("hello world".getBytes())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. 在第一种情况下,您使用JGroups的辅助方法来设置和检索对象,在后一种情况下,您需要自己进行(反序列化)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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