A variety of VMware GemFire clients can be used to connect your application to a VMware GemFire instance. This section provides a brief introduction, along with examples of how to connect, put, and get with a GemFire instance, for the following clients:
Before starting any of the following examples, make sure you have access to a VMware GemFire instance.
To use a Java client with VMware GemFire, you must add the dependencies that are appropriate for your application. The GemFire dependencies are available from the Pivotal Commercial Maven Repo. Access to the Pivotal Commercial Maven Repository requires a one-time registration step to create an account.
To add VMware GemFire to a Maven or Gradle project
Add the GemFire repository to your project:
Maven Add the following to the pom.xml
file:
<repositories>
<repository>
<id>gemfire-release-repo</id>
<name>Pivotal GemFire Release Repository</name>
<url>https://commercial-repo.pivotal.io/data3/gemfire-release-repo/gemfire</url>
</repository>
</repositories>
Gradle Add the following to the build.gradle
file:
repositories {
maven {
credentials {
username "$gemfireRepoUsername"
password "$gemfireRepoPassword"
}
url = uri("https://commercial-repo.pivotal.io/data3/gemfire-release-repo/gemfire")
}
}
Add your Pivotal Commercial Maven Repository credentials.
Maven Add the following to the .m2/settings.xml
file. Replace MY-USERNAME@example
and MY-DECRYPTED-PASSWORD
with your Pivotal Commercial Maven Repository credentials.
<settings>
<servers>
<server>
<id>gemfire-release-repo</id>
<username>MY-USERNAME@example.com</username>
<password>MY-DECRYPTED-PASSWORD</password>
</server>
</servers>
</settings>
Gradle Add the following to the local .gradle/gradle.properties
or project gradle.properties
file. Replace MY-USERNAME@example
and MY-DECRYPTED-PASSWORD
with your Pivotal Commercial Maven Repository credentials.
gemfireRepoUsername=MY-USERNAME@example.com
gemfireRepoPassword=MY-DECRYPTED-PASSWORD
Add the dependencies to the project.
Maven Add the following to your pom.xml
file. Replace VERSION with the version of VMware GemFire being used for the project.
<dependencies>
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>gemfire-core</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
Gradle Add the following to your build.gradle
file. Replace $VERSION with the version of VMware GemFire being used for the project.
dependencies {
implementation "com.vmware.gemfire:gemfire-core:$VERSION"
}
For the following client examples, start a simple cluster and create an example region.
$ gfsh
start locator
start server
create region --name=helloWorld --type=PARTITION
The following is an example of connecting to the VMware GemFire cluster started above.
This example - Creates a ClientCache
, with cluster connection information. - Creates a client side PROXY Region (“helloWorld”) that represents the helloWorld
region that was created on the server. - PUTs data into the helloWorld region. - GETs that data from the helloWorld region. - Prints the value on the command line.
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
public class HelloWorldApplication {
public static void main(String[] args) {
ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334).create();
Region<String, String>
helloWorldRegion =
cache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create("helloWorld");
helloWorldRegion.put("1", "HelloWorldValue");
String value1 = helloWorldRegion.get("1");
System.out.println(value1);
cache.close();
}
}
Build and run the application. You should see ‘HelloWorldValue’ printed in the command line.
Spring Boot for VMware GemFire provides the convenience of Spring Boot’s convention over configuration approach by using auto-configuration with Spring Framework’s powerful abstractions and highly consistent programming model to simplify the development of VMware GemFire applications.
The Spring Boot for VMware GemFire dependencies are available from the Pivotal Commercial Maven Repository. Access to the Pivotal Commercial Maven Repository requires a one-time registration step to create an account.
Spring Boot for VMware GemFire requires users to add the GemFire repository to their projects.
To add Spring Boot for VMware GemFire to a project:
In a browser, navigate to the Pivotal Commercial Maven Repository.
Click the Create Account link.
Complete the information in the registration page.
Click Register.
After registering, you will receive a confirmation email. Follow the instruction in this email to activate your account.
After account activation, log in to the Pivotal Commercial Maven Repository to access the configuration information found in gemfire-release-repo.
Add the GemFire repository to your project:
Maven: Add the following block to the pom.xml
file:
<repository>
<id>gemfire-release-repo</id>
<name>Pivotal GemFire Release Repository</name>
<url>https://commercial-repo.pivotal.io/data3/gemfire-release-repo/gemfire</url>
</repository>
Gradle: Add the following block to the repositories
section of the build.gradle
file:
repositories {
mavenCentral()
maven {
credentials {
username "$gemfireRepoUsername"
password "$gemfireRepoPassword"
}
url = uri("https://commercial-repo.pivotal.io/data3/gemfire-release-repo/gemfire")
}
}
Add your Pivotal Commercial Maven Repository credentials.
Maven: Add the following to the .m2/settings.xml
file. Replace MY-USERNAME@example
and MY-DECRYPTED-PASSWORD
with your Pivotal Commercial Maven Repository credentials.
<settings>
<servers>
<server>
<id>gemfire-release-repo</id>
<username>MY-USERNAME@example.com</username>
<password>MY-DECRYPTED-PASSWORD</password>
</server>
</servers>
</settings>
Gradle: Add the following to the local (.gradle/gradle.properties
) or project gradle.properties
file. Replace MY-USERNAME@example
and MY-DECRYPTED-PASSWORD
with your Pivotal Commercial Maven Repository credentials.
gemfireRepoUsername=MY-USERNAME@example.com
gemfireRepoPassword=MY-DECRYPTED-PASSWORD
After you have set up the repository and credentials, add the Spring Boot for VMware GemFire dependency to your application.
For version 1.0.0:
Maven: Add the following to your pom.xml
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available.
<dependencies>
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>spring-boot-2.7-gemfire-9.15</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
Gradle: Add the following to your build.gradle
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available.
dependencies {
implementation "com.vmware.gemfire:spring-boot-2.7-gemfire-9.15:VERSION"
}
For version 1.1.0 and later:
Starting in version 1.1.0, you will be required to “Bring Your Own GemFire,” which will allow for improved flexibility with GemFire patch versions. In addition to the Spring Boot for VMware GemFire dependency, you must add an explicit dependency on the desired version of GemFire. The required dependencies will differ for clients and servers.
For clients:
Maven: Add the following to your pom.xml
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available and GEMFIRE_VERSION
with the version of VMware GemFire being used for the project.
<dependencies>
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>spring-boot-2.7-gemfire-9.15</artifactId>
<version>VERSION</version>
</dependency>
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>geode-core</artifactId>
<version>GEMFIRE_VERSION</version>
</dependency>
<!--if using continuous queries-->
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>geode-cq</artifactId>
<version>GEMFIRE_VERSION</version>
</dependency>
</dependencies>
Gradle: Add the following to your build.gradle
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available and GEMFIRE_VERSION
with the version of VMware GemFire being used for the project.
dependencies {
implementation "com.vmware.gemfire:spring-boot-2.7-gemfire-9.15:VERSION"
implementation "com.vmware.gemfire:geode-core:GEMFIRE_VERSION"
// if using continuous queries
implementation "com.vmware.gemfire:geode-cq:GEMFIRE_VERSION"
}
For servers:
NOTE: The server dependencies are only required if the user is starting an embedded GemFire server using Spring.
Maven: Add the following to your pom.xml
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available and GEMFIRE_VERSION
with the version of VMware GemFire being used for the project.
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>spring-boot-2.7-gemfire-9.15</artifactId>
<version>VERSION</version>
</dependency>
<dependency>
<groupId>com.vmware.gemfire</groupId>
<artifactId>geode-server-all</artifactId>
<version>GEMFIRE_VERSION</version>
<exclusions>
<exclusion>
<groupId>com.vmware.gemfire</groupId>
<artifactId>geode-log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
Gradle: Add the following to your build.gradle
file. Replace VERSION
with the current version of Spring Boot for VMware GemFire available and GEMFIRE_VERSION
with the version of VMware GemFire being used for the project.
dependencies {
implementation "com.vmware.gemfire:spring-boot-2.7-gemfire-9.15:VERSION"
implementation ("com.vmware.gemfire:geode-server-all:GEMFIRE_VERSION"){
exclude group: 'com.vmware.gemfire', module: 'geode-log4j'
}
}
Your application is now ready to connect with your GemFire instance.
Spring Boot for VMware GemFire is powerful and robust. To confirm that your project is using the Spring for GemFire dependencies correctly, download the Hello World! application and update the appropriate files for your credentials.
Additional Resources
To begin using the VMware GemFire .NET Framework Native Client, first download the VMware GemFire .NET Framework Client library from the Tanzu Network.
Uncompress the distribution archive, which may be a ZIP archive or a compressed tar file (.tar.gz or .tgz). For example:
$ unzip pivotal-gemfire-nativeclient-windows-64bit-10.x.y.zip
or
$ tar xvzf pivotal-gemfire-nativeclient-linux-64bit-10.x.y.tar.gz
VMware.GemFire.dll
and VMware.GemFire.pdb
files to your project.In your .csproj
file add a reference to the dll.
<ItemGroup>
<Reference Include="VMware.GemFire.dll">
<HintPath>..\VMware.GemFire.dll</HintPath>
</Reference>
</ItemGroup>
using System;
using Apache.Geode.Client;
class Program
{
static void Main(string[] args)
{
var cache = new CacheFactory()
.Set("log-level", "none")
.Create();
cache.GetPoolManager()
.CreateFactory()
.AddLocator("localhost", 10334)
.Create("pool");
var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
.SetPoolName("pool");
var region = regionFactory.Create<string, string>("example_userinfo");
Console.WriteLine("Storing id and username in the region");
const string rtimmonsKey = "rtimmons";
const string rtimmonsValue = "Robert Timmons";
const string scharlesKey = "scharles";
const string scharlesValue = "Sylvia Charles";
region.Put(rtimmonsKey, rtimmonsValue);
region.Put(scharlesKey, scharlesValue);
Console.WriteLine("Getting the user info from the region");
var user1 = region.Get(rtimmonsKey, null);
var user2 = region.Get(scharlesKey, null);
Console.WriteLine(rtimmonsKey + " = " + user1);
Console.WriteLine(scharlesKey + " = " + user2);
Console.WriteLine("Removing " + rtimmonsKey + " info from the region");
if (region.Remove(rtimmonsKey))
{
Console.WriteLine("Info for " + rtimmonsKey + " has been deleted");
}
else
{
Console.WriteLine("Info for " + rtimmonsKey + " has not been deleted");
}
cache.Close();
}
}
Additional Resources
To begin using the VMware GemFire C++ Native Client, first download the VMware GemFire C++ Client library from the Tanzu Network.
Uncompress the distribution archive, which may be a ZIP archive or a compressed tar file (.tar.gz or .tgz). For example:
$ unzip pivotal-gemfire-nativeclient-windows-64bit-10.x.y.zip
or
$ tar xvzf pivotal-gemfire-nativeclient-linux-64bit-10.x.y.tar.gz
#include <iostream>
#include <geode/CacheFactory.hpp>
#include <geode/PoolManager.hpp>
#include <geode/RegionFactory.hpp>
#include <geode/RegionShortcut.hpp>
using namespace vmware::gemfire::client;
int main(int argc, char** argv) {
auto cache = CacheFactory()
.set("log-level", "none")
.create();
cache.getPoolManager()
.createFactory()
.addLocator("localhost", 10334)
.create("pool");
auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY);
auto region = regionFactory.setPoolName("pool").create("example_userinfo");
std::cout << "Storing id and username in the region" << std::endl;
region->put("rtimmons", "Robert Timmons");
region->put("scharles", "Sylvia Charles");
std::cout << "Getting the user info from the region" << std::endl;
auto user1 = region->get("rtimmons");
auto user2 = region->get("scharles");
std::cout << " rtimmons = "
<< std::dynamic_pointer_cast<CacheableString>(user1)->value()
<< std::endl;
std::cout << " scharles = "
<< std::dynamic_pointer_cast<CacheableString>(user2)->value()
<< std::endl;
std::cout << "Removing rtimmons info from the region" << std::endl;
region->remove("rtimmons");
if (region->existsValue("rtimmons")) {
std::cout << "rtimmons's info not deleted" << std::endl;
} else {
std::cout << "rtimmons's info successfully deleted" << std::endl;
}
cache.close();
}
Additional Resources