Git Product home page Git Product logo

nodejs-scala-connector's Introduction

DISCLAIMER: nodejs-scala-connector is a proof-of-concept implementation

Asynchronous nature of node.js and its capabilities in handling huge number of connections (with a great potential for building COMET web-apps that doesn't suck) is extremely appealing. However, being a standalone solution (web-server, TCP-server etc), connecting node.js to another ecosystems is not that straightforward (though there're known options of extending node.js functionalities via C++ addons).

The most popular approach of bridging node.js to JVM (Ruby, etc) is setting up a message-bus (e.g. lightweight Redis Pub/Sub) between system components. The benefit of this approach is that you can have durable subscription and guaranteed delivery almost for free (the messages sent from node.js to JVM and vise versa aren't lost even if the system crashes). On the other hand, without a careful configuration and in-life monitoring, messaging bus can turn into a bottleneck and additional source of the headaches.

nodejs-scala-connector is an alternative approach for linking node.js to Scala (JVM) - no mediators are involved and system components communicate to each other directly.

Scala Remote Actors are accessible via TCP - multiple Actors can be registered on one node. Actors protocol is fairly simple, and the biggest problem is that remote actors marshal messages with Java Serialization facility (in order to achieve the best performance), and therefore non-Java applications can't access remote actors directly. Protocol-buffers is an extensible alternative to native serialization that can be understood by a variety of languages: protobuf drivers exist for Java, Python, C++, node.js etc. nodejs-scala-connector modifies standard remote actor in order to serialize messages into protobuf. On the node.js side, net.Stream is used to asynchronously communicate with actors via TCP. ###Sample code of an actor proxy

// Create new proxy for the remote actor
var actorProxy = actors.createActorProxy('10.6.122.29', 12345, 'server')

// Define handler to receive message from the actor asynchronously. Handler is a function that
// maps FQCN of the protocol stub used by the actor and function that handles serialized response
actorProxy.receive({
    'com.vasilrem.remote.protocol.RemoteActorProtocol$StringMessage': function(data){
        console.log('Remote actor responded with: ' + StringMessage.parse(data).message)
        actorProxy.end()
        actorProxy.destroy()
    }
})

// When proxy is loaded, start sending messages
actorProxy.on('ready', function(){
    actorProxy.send(
        'com.vasilrem.remote.protocol.RemoteActorProtocol$StringMessage',
        StringMessage.serialize({
            message: 'Message from node.js!'
        }))
})

nodejs-scala-connector's People

Contributors

remeniuk avatar

Watchers

James Cloos avatar reneX avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.