-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support binary message #28
Comments
Supporting binary messages is a bit harder in Java than Ruby. Ruby allows (and often expects) a string to hold binary data. In Java that's not the case. When converted from binary to a String, Java will validate the payload to make sure it conforms to a certain encoding. In the case of NATS it assumes UTF-8. At decoding time then, how do I know of the message payload is text or binary? Have you verified if the Go NATS server supports binary messages? Any support for binary messages is a low priority for me since my only use case for NATS is to support Cloud Foundry and Cloud Foundry doesn't use binary messages. |
I actually tried to play with the idea and it shouldn't be hard to implement. Instead of "a string to hold binary data", in Java, we just store stuff as bytes internally. It may be byte[](not preferred to avoid the copy) or ByteBuffer or ByteBuf (depends on Netty, not a good idea to expose in API) . In my experiment I just use ByteBuf and change the method signature to ByteBuf. So it is the message user to decide the encoding and choose to call getBytes or getString(Charset) or getUtf8String(). No I didn't verify GNATSD. But as binary is more efficient than text, I don't see any reason they won't fix any bug. Anyway, I view it as a future optimization option for now. I hope I'll get to the point that need such optimization. :-) |
I like this suggestion. I'll look into holding the ByteBuf in the message and then lazily exposing it as a String or byte[]. I definitely don't want to expose Netty in the NATS client API. I'll have some time in a week or so to start making some of these changes. Thanks for your feedback @mingfai! |
Hi there. What about the commit of @mingfai ? Could it after all get into the codebase? Regards Thomas |
if your app is not performance sensitive, and you don't want to wait or patch the lib yourself, consider to encode your byte[] to base64 string |
I agree that being able to send/receive binary messages would be a very NATS, of course, still has valid use cases. However, by the end of the I would be really interested to see somebody build Java based NATS -Mike On Tue, Apr 14, 2015 at 4:44 AM, Mingfai Ma notifications@github.com
|
NATS itself does support binary message
https://github.com/derekcollison/nats/blob/master/spec/binary_msg_spec.rb
The text was updated successfully, but these errors were encountered: