我目前正在架构一个web应用程序,它将使用node.js进行基本路由。这个应用程序的某些部分需要更多的处理器,我想用golang来处理这些部分。但是,我不确定在这两种语言之间安装和通信的最佳方法。我正在使用AmazonElasticBean秸秆进行初始测试,因此任何细节都可以针对该平台。
实质上,它归结为以下两个问题:
1)如何在亚马逊node.js EC2上安装EC2和高丽码头映像?亚马逊有一个或另一个的指南,但不是两者都有。
2)将处理器密集型任务从node.js卸载到golang代码基的最佳方法是什么(我可以对RPC进行成像,或者只在某个本地主机端口上运行golang,但我对这类事情还不熟悉)?golang的任务可能是严肃的数字运算或复杂的图形搜索。
谢谢你的指导。
发布于 2015-05-07 00:46:01
1. If the work you are doing takes a long time it may not be appropriate to have the user wait for a response. For background tasks you can use a queue (like Redis' [rpoplpush](http://redis.io/commands/rpoplpush) or a real queue like Kafka or RabbitMQ, or since you're using Amazon: [SQS](http://aws.amazon.com/sqs/)). Push your job as a JSON object onto the queue, then write a Go program that pulls from the queue, does its processing and then writes the final result somewhere.
2. Go has a [jsonrpc library](http://golang.org/pkg/net/rpc/jsonrpc/). You can communicate over TCP, serialize a request in Node, read it in Go, then deserialize the response in Node. It's the jsonrpc 1.0 protocol and for TCP all you have to do is add some message framing (prefix your json string with a length) or just newline separate each request / response.
3. Write a standard HTTP service in Go and just make HTTP calls from NodeJS. (PUT/POST/GET)
https://stackoverflow.com/questions/30004689
复制相似问题