Basic Netty pipeline question

28 views
Skip to first unread message

crunc...@gmail.com

unread,
Apr 20, 2017, 11:29:52 AM4/20/17
to Netty discussions
I just got started with Netty and I'm trying to understand how to set up my app.  Basically I need to take in the raw bytes, parse the message type, do some application logic like talking to a database, and then either return the requests in some scenarios, or talk to other systems.  I created a subclass of ByteToMessageDecoder and I parse the message type, and get the payload I want properly.  Something that looks like: 

@Override
   
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
     
// find the message type from first bit
     
int messageType = in.getByte(0);

     
if (messageType == MessageType.VERSION) {
           
out.add(createVersionMessageType(in.readBytes())
     
} else if (messageType == MessageType.INFO) {
           
out.add(createInfoMessageType(in.readBytes())
     
}
     
//... more message types ....
}

Then do I create MessageToMessageDecoder<MessageType> in order for members of the ChannelPipeline to ignore messages of the types it does not care about, and handle the types it does care about?

Is there a "best practice" on where I should do my application logic like talking to a database and validating data?  

Thanks
Reply all
Reply to author
Forward
0 new messages