Products
Clients
Extensions
This guide walks you through setting up your local development environment using VMware GemFire, the VMware GemFire node.js client, and a Book Service example.
Book Service
When developing and testing your application locally, you can use VMware GemFire.
Download the .zip or .tar file from the VMWare GemFire Product Page.
Unzip or expand the file.
Configure the VMware GemFire environment variables:.
macOS/Unix/Linux
$ export GEMFIRE_HOME=/Users/MyGemFire $ export PATH=$GEMFIRE_HOME/bin:$PATH
Windows
C:> set GEMFIRE_HOME=c:\Users\MyGemFire C:> set PATH=%GEMFIRE_HOME%\bin;%PATH%
In a terminal type
gfsh version
You should see something similar to
gfsh version 1.10.0
VMware GemFire is now installed on your machine.
This guide allows you to test that your local environment is set up correctly and demonstrates how VMware GemFire will improve the read performance of your application.
This guide uses a Book Service example that allows a user to look up books by ISBN or put new books into the service.
Clone the node examples from the GemFire Node Examples repository.
$ git clone https://github.com/gemfire/node-examples.git
To run the Book Service example, you must download and install the VMware GemFire Node.js client library.
In a terminal, change your working directory to node-examples/book-service, and npm install the VMware GemFire Node.js client you downloaded above, into your project directory.
node-examples/book-service
npm install
$ npm install /project/gemfire-nodejs-client-2.0.0.tgz $ npm update
The local environment mocks the services binding that would exist for a Tanzu Application Service (TAS) environment. A TAS environment injects the services binding through a VCAP_SERVICES environment variable.
VCAP_SERVICES
Set this environment variable:
Mac and Linux
$ export VCAP_SERVICES='{"p-cloudcache":[{"label":"p-cloudcache","provider":null,"plan":"dev-plan","name":"pcc-dev","tags":["gemfire","cloudcache","database","pivotal"],"instance_name":"pcc-dev","binding_name":null,"credentials":{"distributed_system_id":"0","gfsh_login_string":"connect --url=https://localhost:7070/gemfire/v1 --user=super-user --password=1234567 --skip-ssl-validation","locators":["localhost[10334]"],"urls":{"gfsh":"https://localhost:7070/gemfire/v1","pulse":"https://localhost:7070/pulse"},"users":[{"password":"1234567","roles":["cluster_operator"],"username":"super-user"},{"password":"1234567","roles":["developer"],"username":"app"}],"wan":{"sender_credentials":{"active":{"password":"no-password","username":"no-user"}}}},"syslog_drain_url":null,"volume_mounts":[]}]}'
C:>set VCAP_SERVICES={"p-cloudcache":[{"label":"p-cloudcache","provider":null,"plan":"dev-plan","name":"pcc-dev","tags":["gemfire","cloudcache","database","pivotal"],"instance_name":"pcc-dev","binding_name":null,"credentials":{"distributed_system_id":"0","gfsh_login_string":"connect --url=https://localhost:7070/gemfire/v1 --user=super-user --password=1234567 --skip-ssl-validation","locators":["localhost[10334]"],"urls":{"gfsh":"https://localhost:7070/gemfire/v1","pulse":"https://localhost:7070/pulse"},"users":[{"password":"1234567","roles":["cluster_operator"],"username":"super-user"},{"password":"1234567","roles":["developer"],"username":"app"}],"wan":{"sender_credentials":{"active":{"password":"no-password","username":"no-user"}}}},"syslog_drain_url":null,"volume_mounts":[]}]}
There are shell scripts in the book-service/scripts directory. The startGemFire script starts up two locators and two cache servers. The locators allow clients to find the cache servers. To simplify local development, the script also creates the single region (analogous to a table in a relational database) that the app uses.
book-service/scripts
startGemFire
Start the scripts in the node-examples/book-service directory
$ ./scripts/startGemFire.sh
C:>powershell .\scripts\startGemFire.ps1
With a current working directory of node-examples/book-service
$ node src/server.js
C:>node .\src\server.js
To add a book to the data service, use a curl command:
$ curl -X PUT \ 'http://localhost:8080/book/put?isbn=0525565329' \ -H 'Content-Type: application/json' \ -d '{ "FullTitle": "The Shining", "ISBN": "0525565329", "MSRP": "9.99", "Publisher": "Anchor", "Authors": "Stephen King" }'
C:>curl -X PUT "http://localhost:8080/book/put?isbn=0525565329" -H "Content-Type: application/json" -d "{\"FullTitle\": \"The Shining\", \"ISBN\": \"0525565329\", \"MSRP\": \"9.99\", \"Publisher\": \"Anchor\", \"Authors\": \"Stephen King\"}"
To look up a book in the data service, use a curl command, specifying the ISBN as a key:
$ curl -X GET 'http://localhost:8080/book/get?isbn=0525565329'
When finished running the example locally, shut down the client and server processes.
In the shell running node, use control-C to stop running the app.
node
control-C
Use a script to tear down the VMware GemFire cluster. With a current working directory of node-examples/book-service
$ ./scripts/shutdownGemFire.sh
C:>powershell .\scripts\shutdownGemFire.ps1
Use a script to remove the directories and files containing GemFire logs created for the cluster. With a current working directory of node-examples/book-service:
$ ./scripts/clearGemFireData.sh
C:>powershell .\scripts\clearGemFire.ps1
Unset the VCAP_SERVICES environment variable to avoid interference with running other examples that would reference this environment variable if it continues to exist.
$ unset VCAP_SERVICES
C:>set VCAP_SERVICES=""
Congratulations! Your local environment is set up and ready to develop with.
Now that you have successfully set up your local development environment, check out some other guides