can netty suport http (tcp short connection) and Google protobuf

483 Views Asked by At

here is my implements,is it right?

public ChannelPipeline getPipeline() throws Exception 
{
    ChannelPipeline p = pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast("protobufDecoder", new ProtobufDecoder(LocalTimeProtocol.Locations.getDefaultInstance()));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
    p.addLast("protobufEncoder", new ProtobufEncoder());
    p.addLast("handler", new LocalTimeServerHandler());
    return p;
}
1

There are 1 best solutions below

0
On

It will not work. You have to write a handler that gets the content of the HTTP request and converts the content of the request (ChannelBuffer) into a protobuf message. Similar work needs to be done for downstream, too.