Geode in 5 minutes

How to Get Apache Geode

You can download Apache Geode from the website, run a Docker image, or install with homebrew on OSX. Application developers can load dependencies from Maven Central.

您可以從網站下載 Apache Geode, 運行 docker 映像, 或在 osx 上使用自制安裝。應用程序開發人員可以從 maven central 加載依賴項。

Maven

<dependencies>    
   <dependency>        
      <groupId>org.apache.geode</groupId>
      <artifactId>geode-core</artifactId>
      <version>$VERSION</version>
   </dependency>
 </dependencies>

Gradle

dependencies {  compile "org.apache.geode:geode-core:$VERSION"}

Start the cluster 啓動集羣

Download Geode by following one of the methods described above, and follow the installation instructions at in the posted manual at http://geode.apache.org/docs/. With a path that contains the bin directory of the installation, start a locator and server:

按照上述方法之一下載 Geode, 並按照 http://geode.apache.org/docs/張貼的手冊中的安裝說明進行操作。
使用包含安裝的 bin 目錄的路徑, 啓動定位器和服務:

$ gfsh
  gfsh> start locator
  gfsh> start server

Create a region:

gfsh> create region --name=hello --type=REPLICATE 

src/main/java/HelloWorld.java

package com.tom.learning.geode;

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 HelloWorld {

    public static void main(String[] args) {

        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");

        region.entrySet().stream().forEach(entry -> {
            System.out.format("key = %s, value = %s \n", entry.getKey(), entry.getValue());
        });

        cache.close();
    }
}

Build and run the HelloWorld example.
構建並運行 HelloWorld.

The application will connect to the running cluster, create a local cache, put some data in the cache, and print the cached data to the console:
程序運行後將連接正在運行的集羣,創建本地緩存,在緩存中放置一些數據,並將緩存數據打印到控制檯:

key = 1, value = hello 
key = 2, value = world 

Finally, shutdown the Geode server and locator:
最後,關閉 Geode 服務和 locator:

gfsh> shutdown --include-locators=true

For more information see the Geode Examples repository or the documentation .
查看更多信息,請查看 Geode Examples 或者文檔

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章