doujing1156 2018-08-21 16:05
浏览 40

微服务消息传递

I am working on a project splitting services off of a monolithic codebase. Currently, the two services I am working on are a login/authentication service, a service providing a few REST API endpoints and a data retrieval service feeding the REST API. I need the services to exchange data with each other, in particular, data retrieval needs to send data to the REST API and REST API needs to exchange authentication requests/responses with the login service.

The technology of choice in go world seems to be protobufs and gRPC. I have been looking into using these, but it seems really inconvenient, so I wonder if I am just doing things wrong.

For example, my data retrieval gets records from an RDBMS and my REST API serves this data as JSON. Normally, I would define a "model" struct for each type of record in the database/API, use reflect annotations for both database and JSON in the struct definitions and used something like sqlx to scan query results into structs and encoding/json to serialize structs into JSON. But if I want to pass the data around using gRPC and protobufs this whole setup goes out of the window. Since protobuf generates its own struct types, I would have to manually implement conversion from SQL rows into protobufs and from protobufs into JSON for every single message type I define. Not that implementing conversions is hard, but it introduces more opportunities for bugs and code fragility and feels like reinventing the wheel.

And this seems like this should be a very common problem. Am I missing some obvious solution?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程