Products
Clients
Extensions
APIs
Before starting the following example make sure you have GemFire installed.
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 Broadcom Support Portal. Login (or register if you have not already) and click Show All Releases and find “Click Green Token For Repository Access” (don’t click the blue text; click the green icon to the right of it).
To add GemFire to a Maven or Gradle project
You will need a Broadcom Support Portal account and a token obtained as described above.
Select My Downloads. Search by Product Name = VMware Tanzu GemFire. Click on VMware Tanzu GemFire. Click on VMware Tanzu GemFire. Scroll down, Show All Releases, scroll down to Click Green Token for Repository Access and click on the green symbol to the far right. Note your email address. Copy your access_token (not including any surrounding quotation marks).
Add the GemFire repository to your project:
pom.xml
<repositories> <repository> <id>gemfire-release-repo</id> <name>Broadcom GemFire Release Repository</name> <url>https://packages.broadcom.com/artifactory/gemfire/</url> </repository> </repositories>
build.gradle
repositories { maven { credentials { username "$gemfireRepoUsername" password "$gemfireRepoPassword" } url = uri("https://packages.broadcom.com/artifactory/gemfire/") } }
Add your Broadcom Maven Repository credentials.
.m2/settings.xml
MY-USERNAME@example
MY-ACCESS-TOKEN
<settings> <servers> <server> <id>gemfire-release-repo</id> <username>[email protected]</username> <password>MY-ACCESS-TOKEN</password> </server> </servers> </settings>
.gradle/gradle.properties
gradle.properties
gemfireRepoUsername=MY-USERNAME@example.com gemfireRepoPassword=MY-ACCESS-TOKEN
Add the dependencies to the project.
<dependencies> <dependency> <groupId>com.vmware.gemfire</groupId> <artifactId>gemfire-core</artifactId> <version>VERSION</version> </dependency> </dependencies>
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 GemFire cluster started above.
This example
ClientCache
helloWorld
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.