简体   繁体   中英

Connector between node.js and Scala (Java)

What is the best way of integrating node.js with Scala (Java)?

The simplest way I see so far is using Redis PubSub as a mediator, with node.js server handling HTTP requests and publishing messages to the request channel (via redis-node-client ), and Scala actors (eg Akka Redis PubSub integration ) subscribed the request channel and publishing computation results to the response channel (subscribed by nodes).

Assuming you'll be using JSON as your message format, you'll find a couple of very good JSON implementations inside the lift framework (which you don't have to use as a web framework, you can happily cherry-pick components from lift-utils).

But if you want to go with a pubsub/actor model (and it's a good choice, depending on your needs) then you could do a lot worse than Akka, as you already suggested.

我已经实现了一个小的概念验证库,用于直接通过TCP(使用protobuf作为编组机制)将node.js连接到Scala Remote Actor。

I don't think that a node.js library implementing the Scala remote actor protocol is really the best way. It may work well for your current application but what if you need to add a third technology to the mix. Can it really be best if it requires writing special support libraries for each language/platform?

The best way to integrate these is to use a general purpose technology for integrating applications of all languages. And more specifically, one which supports actor-based message sending. Fortunately, AMQP and ZeroMQ both fit into that space and both can be used with node.js or scala. In addition, the libraries for AMQP and ZeroMQ will be more heavily used than any special purpose node-scala connector, therefore buigs will get fixed and newer versions will get supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM