A variety of VMware GemFire clients can be used to connect your application to a 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:

Install VMware GemFire

Before starting any of the following examples, make sure you have access to a GemFire instance.

VMware GemFire Java Client

To use a Java client with 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.

Adding GemFire to a Project

To add GemFire to a Maven or Gradle project

  1. In a browser, navigate to the Pivotal Commercial Maven Repository.
  2. Click the Create Account link.
  3. Complete the information in the registration page and accept the EULA.
  4. Click Register.
  5. After registering, you will receive a confirmation email. Follow the instruction in this email to activate your account.
  6. 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")
        }
      }
      
  7. 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
      
  8. 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"
      }
      

Starting a VMware GemFire Cluster

For the following client examples, start a simple cluster and create an example region.

  1. With GemFire installed or available, in a terminal start the GemFire shell (GFSH)
    $ gfsh 
    
  2. Using GFSH start a locator
    start locator
    
  3. Next, use GFSH to start a server
    start server
    
  4. Create a region called “helloWorld”.
    create region --name=helloWorld --type=PARTITION 
    

Simple Put and Get

The following is an example of connecting to the 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

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.

Adding GemFire to a Project

The Spring Boot for VMware GemFire dependencies are available from the Pivotal Commercial Maven Repository. Access to the Pivotal Commercial Maven Repository is 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.

  1. In a browser, navigate to the Pivotal Commercial Maven Repository.
  2. Click the Create Account link.
  3. Complete the information in the registration page and accept the EULA.
  4. Click Register.
  5. After registering, you will receive a confirmation email. Follow the instruction in this email to activate your account.
  6. 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 {
        mavenCentral()
        maven {
            credentials {
                username "$gemfireRepoUsername"
                password "$gemfireRepoPassword"
            }
            url = uri("https://commercial-repo.pivotal.io/data3/gemfire-release-repo/gemfire")
        }
      }
      
  7. 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
      
  8. Add the dependencies to the project.

    • 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"
      }
      

Building an Application with Spring Boot for VMware GemFire

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


VMware GemFire .NET Framework Native Client

To begin using the VMware GemFire .NET Framework Native Client, first download the VMware GemFire .NET Framework Client library from the Tanzu Network.

Download the Native Clients Libraries from the Tanzu Network

  1. In a browser, navigate to the VMware Tanzu GemFire download page.
  2. From the Releases: drop-down menu, select the most recent version of VMware Tanzu GemFire Native Client.
  3. Select the version that best suits your development platform, and download it.
  4. 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
    
  5. Add the VMware.GemFire.dll and VMware.GemFire.pdb files to your project.
  6. In your .csproj file add a reference to the dll.

    <ItemGroup>
         <Reference Include="VMware.GemFire.dll">
           <HintPath>..\VMware.GemFire.dll</HintPath>
         </Reference>
    </ItemGroup>
    

Put, Get and Remove with VMware GemFire Native .NET Client (C#)

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


VMware GemFire Native C++ Client

To begin using the VMware GemFire C++ Native Client, first download the VMware GemFire C++ Client library from the Tanzu Network.

Download the Native Clients Libraries from the Tanzu Network

  1. In a browser, navigate to the VMware Tanzu GemFire download page.
  2. From the Releases: drop-down menu, select the most recent version of VMware Tanzu GemFire Native Client.
  3. Select the version that best suits your development platform, and download it.
  4. 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
    

Put, Get, and Remove with VMware GemFire Native C++ Client

#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

check-circle-line exclamation-circle-line close-line
Scroll to top icon