Building a service that talks protocol buffers

Trustin Lee tlee at redhat.com
Wed Mar 11 15:34:29 EDT 2009


On Wed, Mar 11, 2009 at 9:22 AM, Utkarsh Srivastava <utkarsh at gmail.com> wrote:
> Hi folks,
>
> Are there any recommendations/examples to follow while building a service
> over Netty? My service has multiple methods and uses protocol buffers for
> message serialization.
>
> Protocol buffers do let you define services, but the generated code expects
> an RPC interface and doesn't look like it can fit cleanly into Netty.
>
> So it looks like the only option is to declare a message such as
>
> message Request{
>     enum RequestType { READ = 1; WRITE = 1; }
>     required RequestType requestType = 1;
>     optional ReadRequest readRequest = 2;
>     optional WriteRequest writeRequest = 3;
> }
>
> And then in the netty handler decide whether its a write call or a read call
> based on the enum, and then pass the appropriate optional field (readRequest
> or writeRequest) to the next handler.
>
> Is this the recommended way or is there something cleaner I can do?

Netty is essentially message-based, and therefore I'd suggest you to
use messages rather than services in protobuf.  This post and the
links in the post might help you:

  * http://groups.google.com/group/protobuf/browse_thread/thread/a96fce6a68506875/8b04c4c9ff065071

Let me know if it was not something that you were looking for.

BTW, you could write / contribute an RPC client / server
implementation based on Netty - it's certainly doable.

HTH,

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list