Google 协议缓冲区和 servlet [英] Google protocol buffers and servlets

查看:60
本文介绍了Google 协议缓冲区和 servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用谷歌协议缓冲区来接受请求并将响应发送回客户端?我正在考虑编写一个接受请求的 servlet.以下思路是否是实现这一点的正确方法:1. 有一个 .proto 文件,它是传入请求的消息定义.2. 编写一个接受这个请求的 servlet,执行查询数据库等各种任务然后发送响应.此响应是否需要单独的 .proto 消息定义,其中包含构成响应的所有字段?3. 客户端会不会只是调用我的 servlet 的 doGet() 方法并传递请求,然后它应该作为 protobuff 对象返回响应?

I am wondering how I can use google protocol buffers to accept a request and send a response back to a client? I am thinking about writing a servlet which will take a request. Is the following trail of thought the correct way to implement this: 1. Have a .proto file which is the message definition for the incoming request. 2. Write a servlet which accepts this request, does various tasks like querying database and then sends a response. Will this response require a separate .proto message definition with all the fields that make up the response? 3. Will the client just invoke the doGet() method of my servlet and pass the request, it should then return a response as a protobuff object?

非常感谢任何建议或想法.

Any suggestion or idea will be very much appreciated.

推荐答案

HI,

我已经启动并运行了.我最终将 http 请求作为帖子发布到我的 servlet.我能够获取请求协议缓冲区,读取请求,进行一些处理,然后发回响应.一旦我开始工作,它实际上非常简单.我们使用 1 .proto 文件来定义请求和响应消息结构.

I have this up and running. I ended up posting a http request as a post to my servlet. I was able to take the request protocol buffer, read the request, do some processing and then send back a response. It was actually really simple once I got it working. We used the 1 .proto file to define the request and response message structure.

这篇关于Google 协议缓冲区和 servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆