Coder Social home page Coder Social logo

googlielmo / hazelcast-nodejs-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hazelcast/hazelcast-nodejs-client

0.0 2.0 0.0 8.33 MB

NodeJS Client for Hazelcast, using Hazelcast Open Client Protocol 1.0 for Hazelcast 3.6 and higher

Home Page: http://hazelcast.github.io/hazelcast-nodejs-client/

License: Apache License 2.0

JavaScript 25.00% Shell 0.68% TypeScript 74.32%

hazelcast-nodejs-client's Introduction

Table of Contents

Hazelcast Node.js Client

NOTE: This project is currently in active development.

Join the chat at https://gitter.im/hazelcast-incubator/hazelcast-nodejs-client

This document explains Node.js client for Hazelcast which uses Hazelcast's Open Client Protocol 1.0. This client works with Hazelcast 3.6 and higher.

Hazelcast is a clustering and highly scalable data distribution platform. With its various distributed data structures, distributed caching capabilities, elastic nature and more importantly with so many happy users, Hazelcast is a feature-rich, enterprise-ready and developer-friendly in-memory data grid solution.

Features

Hazelcast Node.js client supports the following data structures and features:

  • Map (including entry processors and PartitionAware keys) and MultiMap
  • ReplicatedMap
  • Near Cache support for Map
  • Queue, Set, and List
  • Lock
  • Smart Client
  • Hazelcast Native Serialization
  • Distributed Object Listener
  • Lifecycle Service
  • Ringbuffer
  • Reliable Topic
  • Semaphore
  • Replicated Map
  • Atomic Long
  • SSL connection support (requires enterprise server)

Installing the Client

Following command installs Hazelcast Node.js client:

npm install hazelcast-client --save

Using the Client

Following script illustrates a basic example in which a map is created in Hazelcast Node.js client and an entry is added to that map:

var HazelcastClient = require('hazelcast-client').Client;
var person = {
    firstName: "Joe",
    lastName: "Doe",
    age: 42
};
var map;
HazelcastClient.newHazelcastClient().then(function (hazelcastClient) {
    map = hazelcastClient.getMap("personMap");
    map.put(1, person).then(function (val) {
        // prints previous value for key `1`
        console.log(val);
    });
    map.get(1).then(function (value) {
        console.log(value);
    })
});

Please see Hazelcast Node.js code samples for more examples.

You can also refer to Hazelcast Node.js API Documentation.

Serialization Considerations

Hazelcast needs to serialize objects in order to be able to keep them in the server memory. For primitive types, it uses Hazelcast native serialization. For other complex types (e.g. JS objects), it uses JSON serialization.

For example, when you try to query your data using predicates, this querying is handled on the server side so Hazelcast does not have to bring all data to the client but only the relevant entries. Otherwise, there would be a lot of unneccessary data traffic between the client and the server and the performance would severely drop. Because predicates run on the server side, the server should be able to reason about your objects. That is why you need to implement serialization on the server side.

The same applies to MapStore. The server should be able to deserialize your objects in order to store them in MapStore.

Regarding arrays in a serializable object, you can use methods like writeIntArray if the array is of a primitive type.

If you have nested objects, these nested objects also need to be serializable. Register the serializers for nested objects and the method writeObject will not have any problem with finding a suitable serializer for and writing/reading the nested object.

If you have arrays of custom objects, you can serialize/deserialize them like the following:

writeData(dataOutput) {
    ...
    dataOutput.writeInt(this.arrayOfCustomObjects);
    this.arrayOfCustomObjects.forEach(function(element) {
        dataOutput.writeObject(element);
    });
    ...
}

readData(dataInput) {
    ...
    var arrayOfCustomObjects = [];
    var lenOfArray = dataInput.readInt();
    for (i=0;i<lenOfArray;i++) {
        arrayOfCustomObjects.push(dataInput.readObject());
    }
    this.arrayOfCustomObjects = arrayOfCustomObjects;
    ...
}

Development

Building And Installing from Sources

Follow the below steps to build and install Hazelcast Node.js client from its source:

  • Clone the GitHub repository https://github.com/hazelcast/hazelcast-nodejs-client.git.
  • Install the dependencies using the command npm install.
  • Compile TypeScript using the command npm run compile.
  • Link the package locally using the command npm link.
  • Run static analysis tool using the command npm run lint

Using Locally Installed Package

  • Change directory to the project directory.
  • Use a locally linked module: npm link hazelcast-client.
  • Tryout the example shown in Using the Client section.

Testing

Testing Prerequisites

  • Java 6+

  • Maven

    Maven automatically downloads hazelcast-remote-controller and hazelcast from maven repository.
    

Running the Tests

Following command starts the tests:

npm test

Release Notes

You can see the release notes for each release on the Releases page.

Mail Group

Please join the mail group if you are interested in using or developing Hazelcast.

http://groups.google.com/group/hazelcast

License

Hazelcast is available under the Apache 2 License. Please see the Licensing appendix for more information.

Copyright

Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.

Visit www.hazelcast.com for more information.

hazelcast-nodejs-client's People

Contributors

mustafaiman avatar ghostinamachine avatar asimarslan avatar bilalyasar avatar gamussa avatar serdaro avatar blicksky avatar zemd avatar gregrluck avatar gitter-badger avatar

Watchers

James Cloos avatar  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.