What can I use for a simple IPC between Go and a program written in arbitrary lang ?

blov · 2018-01-11 22:30:14 · 689 次点击    
这是一个分享于 2018-01-11 22:30:14 的资源,其中的信息可能已经有所发展或是发生改变。


评论:

jh125486:

How arbitrary? gRPC seems to do well. And if that isn’t supported there’s good old fashioned JSON.

Loves_Portishead:

+1 for GRPC

BadlyCamouflagedKiwi:

What's the relationship between the two programs? If one spawns another then communication over stdin / stdout can work well - although you also need a serialisation format, JSON is likely easy and protobufs are nice for more structure.

(Am also +1 for gRPC but you're after something lighter so...)

lhxtx:

gRPC is fantastic.

holyjeff:

grpc or json are both possible though I think they are both a bit too much. Is there a lightweight way you can recommend ?

SeerUD:

In what way do you mean a bit much?

gRPC is actually really easy to use, but if you want to get simpler (though more difficult) then you could always just use a raw TCP connection and pass bytes around yourself - but why go through all of that hassle if you don't need to? gRPC will also be more lightweight than making some JSON web service too since Protobuf is a faster (to encode and decode) and more lightweight data format.

dfndoe:

If go is spawning the other language then json on stdin/stdout is pretty straightforward and makes for a very language agnostic interface.

meta_leap:

If go is spawning the other language then json on stdin/stdout is pretty straightforward

Even when it's the other way around, too! I'm quite keen on line-based IPC if the processes are all under your own development/control and are all "reasonably fast" with regards to eg. JSON. I struggle to find a better protocol for line-based text-based IPC ---custom stuff always seems to end up growing to the point where switching to JSON is the sane choice--- and I like line-based-text-based because one can pose as the-other-process interactively via the terminal when it becomes necessary for a bit. Also it's handy to have the 2 output channels built-in to every process, for example "stdout for IPC, stderr for debug-logging to the other side".

Performance-wise seems fine if the processes are "ping-ponging structured messages" between each other, rather than say continuously-streaming (where raw-bytes serializing might prove more efficient).


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

689 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传