This article describes how to use GemFire native client from NodeJS.
GemFire officially supports a GemFire Java client and a C#/C++ GemFire Native Client, but does not provide an official interface for NodeJS. There are, however, some customers who are using NodeJS to develop cross-platform, event-driven, and rich web applications who would like to call the GemFire native client library like other NodeJS packages. This article provides a brief guide to using the open-source "node-GemFire" NodeJS package.
Please note that "node-GemFire" is open source software and is not officially supported by Pivotal, though it is created and tested by GemFire team members.
.bashrc
user profile
#an Example of NodeJS PATH export PATH=$PATH:/home/gpadmin/apps/nodejsclient/node-v0.10.46-linux-x64/bin
Install the GemFire Native Client.
Download the GemFire Native Client 8.1.x Linux Distribution zip file from Pivotal Network [2]. Unzip the file and add the following environmental settings to the .
bashrc
user profile. For details, please refer to the GemFire documentation [3].
#an Example of GemFire Native Client Environment Variables export GFCPP=/home/gpadmin/apps/NativeClient_Linux_64bit_8100_b6258 export PATH=$PATH:$GFCPP/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GFCPP/lib
Install node-GemFire from the NPM package
Install the node-GemFire module with the NPM package management tool using the following commands:
$mkdir /home/gpadmin/apps/nodejsclient/GemFire $cd /home/gpadmin/apps/nodejsclient/GemFire $NODE_TLS_REJECT_UNAUTHORIZED=0 npm install --save GemFire
Please note that this step will download a precompiled binary, such as [node-GemFire/0.1.19/GemFire-v0.1.19-node-v11-linux-x64.tar.gz
] from the download site[6]. Here, [v11] is the Node ABI version so please make sure that there is a precompiled build provided at this site with the correct node-GemFire version and NodeJS ABI version and platform. Otherwise, you may see some error when installing this package.
After installing the node-GemFire module successfully, add the following environment settings to the .bashrc
user profile
#an Example of node modules export NODE_PATH=/home/gpadmin/apps/nodejsclient/GemFire/node_modules
GemFire Native Client properties may be configured using the gfcpp.properties
file. Place this file in the current working directory of your node application.
As an example, the following settings will turn on statistics collection: Set the log level to "fine
" and redirect log output to a file:
statistic-sampling-enabled=true log-level=fine log-file=gemfireclient.log
You can find a list of the available options for the gfcpp.properties
file in the documentation [4].
Now you can run a GemFire client from NodeJS to connect with your existing GemFire cluster.
An example is shown below:
var GemFire = require('GemFire'); GemFire.configure('ExampleClient.xml'); var cache = GemFire.getCache(); var region = cache.getRegion('myRegion');
You can find detailed API usage in the node-GemFire documentation [5].
A full NodeJS example:exampleClient.js/ExampleClient.xml is attached for your reference.
Following is a screenshot of running this exampleClient.js.