-
Notifications
You must be signed in to change notification settings - Fork 56
Building Apache Geode
General Notes:
- When following the steps below please use a standard permission user unless otherwise specified.
- A directory
/<source_root>/
will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.
Apache Geode binaries are available and can be downloaded from here. To use these binaries, Java needs to be installed on mentioned distributions.
Note: Apache Geode(v1.15.1) was verified at the time of creation of these instructions
-
RHEL (7.8, 7.9, 8.6, 8.7, 9.0, 9.1)
sudo yum install -y wget unzip tar java-1.8.0-openjdk-devel
-
SLES (12 SP5, 15 SP4)
sudo zypper install -y wget unzip which tar gzip java-1_8_0-openjdk-devel
-
Ubuntu (20.04, 22.04, 22.10, 23.04)
sudo apt-get update sudo apt-get install -y wget unzip tar openjdk-8-jdk
export JAVA_HOME=<path to java>
export PATH=$JAVA_HOME/bin:$PATH
Extract binary tar to /<source_root>/
and follow steps given below
export SOURCE_ROOT=/<source_root>/
export PATH=$SOURCE_ROOT/<apache_geode_binary_directory>/bin:$PATH
-
Check installed Apache Geode version
gfsh version
-
To start locator and server, run following commands :
gfsh gfsh> start locator gfsh> start server
-
Create a region
gfsh> create region --name=hello --type=REPLICATE
Write a client application using gradle in different terminal.
-
Install Gradle
export SOURCE_ROOT=/<source_root>/ cd $SOURCE_ROOT wget https://services.gradle.org/distributions/gradle-5.5-bin.zip unzip -q gradle-5.5-bin.zip export JAVA_HOME=<path to java> export PATH=$JAVA_HOME/bin:$PATH:$SOURCE_ROOT/gradle-5.5/bin
-
Create
$SOURCE_ROOT/build.gradle
file with following contentsapply plugin: 'java' apply plugin: 'application' mainClassName = 'HelloWorld' repositories { mavenCentral() } dependencies { compile 'org.apache.geode:geode-core:1.4.0' runtime 'org.slf4j:slf4j-log4j12:1.7.24' }
-
Create directory
$SOURCE_ROOT/src/main/java
and create a file at$SOURCE_ROOT/src/main/java/HelloWorld.java
with following contentsimport java.util.Map; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.*; public class HelloWorld { public static void main(String[] args) throws Exception { ClientCache cache = new ClientCacheFactory() .addPoolLocator("localhost", 10334) .create(); Region<String, String> region = cache .<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create("hello"); region.put("1", "Hello"); region.put("2", "World"); for (Map.Entry<String, String> entry : region.entrySet()) { System.out.format("key = %s, value = %s\n", entry.getKey(), entry.getValue()); } cache.close(); } }
-
Build and run the HelloWorld example:
gradle run
Gradle build is successful as the application will connect to the running cluster, create a local cache, put data in the cache, and print the cached data to the console:
key = 1, value = Hello key = 2, value = World
-
Shutdown the Geode server and locator in earlier terminal:
gfsh> shutdown --include-locators=true
The information provided in this article is accurate at the time of writing, but on-going development in the open-source projects involved may make the information incorrect or obsolete. Please open issue or contact us on IBM Z Community if you have any questions or feedback.