Movatterモバイル変換


[0]ホーム

URL:


hazelcast-client
TypeScript icon, indicating that this package has built-in type declarations

5.3.0 • Public • Published

Hazelcast Node.js Client

NPM versionChat on SlackFollow on Twitter


What is Hazelcast?

Hazelcast is a distributed computation and storage platform for consistently low-latency querying,aggregation and stateful computation against event streams and traditional data sources. It allows you to quickly buildresource-efficient, real-time applications. You can deploy it at any scale from small edge devices to a large cluster ofcloud instances.

A cluster of Hazelcast nodes share both the data storage and computational load which can dynamically scale up and down.When you add new nodes to the cluster, the data is automatically rebalanced across the cluster, and currently runningcomputational tasks (known as jobs) snapshot their state and scale with processing guarantees.

For more info, check out Hazelcastrepository.

What is Hazelcast Node.js Client?

Hazelcast Node.js client is a way to communicate to Hazelcast clusters and access the cluster data via Node.js.The client provides a Promise-based API with a builtin support for native JavaScript objects.

Installation

Hazelcast

Hazelcast Node.js client requires a working Hazelcast cluster to run. This cluster handles the storage andmanipulation of the user data.

A Hazelcast cluster consists of one or more cluster members. These members generally run on multiple virtual orphysical machines and are connected to each other via the network. Any data put on the cluster is partitioned tomultiple members transparent to the user. It is therefore very easy to scale the system by adding new members asthe data grows. Hazelcast cluster also offers resilience. Should any hardware or software problem causes a crashto any member, the data on that member is recovered from backups and the cluster continues to operate without anydowntime.

The quickest way to start a single member cluster for development purposes is to use ourDocker images.

docker run -p 5701:5701 hazelcast/hazelcast

This command fetches the latest Hazelcast version. You can find all available tagshere.

You can also use our ZIP or TARdistributionsas describedhere.

Client

npm install hazelcast-client

Overview

Usage

const{ Client}=require('hazelcast-client');// Connect to Hazelcast clusterconstclient=awaitClient.newHazelcastClient();// Get or create the 'distributed-map' on the clusterconstmap=awaitclient.getMap('distributed-map');// Put 'key', 'value' pair into the 'distributed-map'awaitmap.put('key','value');// Get the value associated with the given key from the clusterconstvalue=awaitmap.get('key');console.log(value);// Outputs 'value'// Shutdown the clientawaitclient.shutdown();

NOTE: For the sake of brevity we are going to omit boilerplate parts in the above code snippet.Refer tothis code sampleto see the complete code.

If you are using Hazelcast and the Node.js client on the same machine, the default configuration should workout-of-the-box. However, you may need to configure the client to connect to cluster nodes that are running ondifferent machines or to customize client properties.

Configuration

const{ Client}=require('hazelcast-client');// Initialize the client with the given configurationconstclient=awaitClient.newHazelcastClient({clusterName:'cluster-name',network:{clusterMembers:['10.90.0.2:5701','10.90.0.3:5701']},lifecycleListeners:[(state)=>{console.log('Lifecycle Event >>> '+state);}]});console.log('Connected to cluster');awaitclient.shutdown();

Refer tothe documentation to learn more about supported configuration options.

Features

  • Distributed, partitioned and queryable in-memory key-value store implementation, calledMap
  • Eventually consistent cache implementation to store a subset of the Map data locally in the memory of the client, calledNear Cache
  • Additional data structures and simple messaging constructs such asSet,MultiMap,Queue,Topic
  • Cluster-wide unique ID generator, calledFlakeIdGenerator
  • Distributed, CRDT based counter, calledPNCounter
  • Distributed concurrency primitives from CP Subsystem such asFencedLock,Semaphore,AtomicLong
  • Integration withHazelcast Cloud
  • Support for serverless and traditional web service architectures withUnisocket andSmart operation modes
  • Ability to listen client lifecycle, cluster state and distributed data structure events
  • andmany more.

Getting Help

You can use the following channels for your questions and development/usage issues:

Contributing

We encourage any type of contribution in the form of issue reports or pull requests.

Issue Reports

For issue reports, please share the following information with us to quickly resolve the problems.

  • Hazelcast and the client version that you use
  • General information about the environment and the architecture you use like Node.js version, cluster size,number of clients, Java version, JVM parameters, operating system etc.
  • Logs and stack traces, if any.
  • Detailed description of the steps to reproduce the issue.

Pull Requests

Contributions are submitted, reviewed and accepted using the pull requests on GitHub. For an enhancement or largerfeature, create a GitHub issue first to discuss.

Development

  1. Clone the GitHubrepository.
  2. Runnpm install to automatically download and install all the required modules.
  3. Do the work.
  4. Hazelcast Node.js client developed using TypeScript. Runnpm run compile to compile TypeScript files to JavaScript.
  5. To have a consistent code style across the code base, Hazelcast Node.js client uses a style checker.Runnpm run lint and fix the reported issues, if any.

Testing

In order to test Hazelcast Node.js client locally, you will need the following:

  • Java 8 or newer
  • Maven

Following command starts the tests:

npmtest

Test script automatically downloadshazelcast-remote-controller and Hazelcast. The script uses Maven to download those.

In order to run specific tests, you can give a pattern to the test command like the following:

npmtest pattern

This command will only run the tests matching the pattern. The pattern can be a string or regex in the same formgrep command accepts.

License

Apache 2.0 License.

Copyright

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

Visitwww.hazelcast.com for more information.

Package Sidebar

Install

npm i hazelcast-client

Weekly Downloads

4,512

Version

5.3.0

License

Apache-2.0

Unpacked Size

2.11 MB

Total Files

997

Last publish

Collaborators

  • hazelcast

[8]ページ先頭

©2009-2025 Movatter.jp