I am doing some sort of encryption which depends of the order of messages sent via a Netty channel. What I am expecting is that if I write message A before message B to a channel then they should be sent to the remote socket in the same order I have written them to the channel. So is the case I need already supported by Netty?
On the other hand Netty's Channel accepts concurrent write calls and I am in doubt my requirement can already met. I had to synchronize on a statefull (a per channel one) encoder today due to currupt state of a data structure. However I am still not sure whether the in-filter synchronization will help my need.
Yes, the messages will get transfered in the same order as you call Channel.write(..). There is nothing you need to worry about here.
Answer picked up from this issue. (Thanks
Scottmitch@github
).Netty can provide "ordering" in the following situations:
EventLoop
thread; OREventLoop
thread (i.e. all writes are being done in other thread(s)).It is subtle but important thing to remember as it can cause painful bugs. If some
channel.write()
calls are coming from application threads and some are coming fromEventLoop
then the writes can seem out of order from application's perspective. See more details on the linked issue.This question seems to be the top search result for Netty write ordering, so wanted to make sure it mentions this important caveat.