apache geode 试用

使用docker 运行,文档参考的官方的5 分钟学习文档

拉取镜像

docker pull apachegeode/geode

启动

docker run -it -p 10334:10334 -p 7575:7575 -p 1099:1099 -p 40404:40404  apachegeode/geode

初始化数据

容器内

start locator
start server
create region --name=hello --type=REPLICATE 

提示信息

create region --name=hello --type=REPLICATE 
     Member | Status
---------------- | ---------------------------------------------
fix-powerful-cup | Region "/hello" created on "fix-powerful-cup"
 
 

简单运行

因为使用了容器,同时我们需要配置一个简单hosts 别名

/etc/hosts
127.0.0.1 55bbae309e69
 

使用maven 管理

  • 项目结构
├── pom.xml
└── src
    ├── main
    ├── java
    └── com
    └── dalong
    └── Application.java
    └── resources
    └── test
        ├── java
        └── resources
 
 
  • 代码说明
    pom.xml
 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dalong.app</groupId>
  <artifactId>dw-jdbc-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
   <dependency>
        <groupId>org.apache.geode</groupId>
        <artifactId>geode-core</artifactId>
        <version>1.8.0</version>
    </dependency>
  </dependencies>
</project>
 
 

application.java

package com.dalong;
import java.util.Map;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.*;
public class Application {
  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");
          for (Map.Entry<String, String> entry : region.entrySet()) {
            System.out.format("key = %s, value = %s\n", entry.getKey(), entry.getValue());
          }
          cache.close();
  }
}
 
 
  • 运行效果
[info 2019/01/10 16:02:11.749 CST <main> tid=0x1] initializing InternalDataSerializer with 0 services
[info 2019/01/10 16:02:11.784 CST <main> tid=0x1] [ThreadsMonitor] New Monitor object and process were created.
[info 2019/01/10 16:02:11.812 CST <StatSampler> tid=0x11] Disabling statistic archival.
[info 2019/01/10 16:02:11.839 CST <main> tid=0x1] Running in client mode
[info 2019/01/10 16:02:11.955 CST <main> tid=0x1] AutoConnectionSource UpdateLocatorListTask started with interval=10000 ms.
[info 2019/01/10 16:02:11.957 CST <main> tid=0x1] Pool DEFAULT started with multiuser-authentication=false
[info 2019/01/10 16:02:12.004 CST <poolTimer-DEFAULT-3> tid=0x1a] Updating membership port. Port changed from 0 to 52778. ID is now bogon(71460:loner):0:b16ec836
key = 1, value = Hello
key = 2, value = World
[info 2019/01/10 16:02:12.084 CST <main> tid=0x1] GemFireCache[id = 1097897234; isClosing = true; isShutDownAll = false; created = Thu Jan 10 16:02:11 CST 2019; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.
[info 2019/01/10 16:02:12.132 CST <main> tid=0x1] Destroying connection pool DEFAULT
 

说明

apache geode 功能还是很强大的,同时也很灵活

参考资料

https://cwiki.apache.org/confluence/display/GEODE/Index#Index-Geodein5minutesGeodein5minutes
https://hub.docker.com/r/apachegeode/geode
https://github.com/rongfengliang/geode-java-demo

posted on 2019-01-10 16:15  荣锋亮  阅读(1411)  评论(0编辑  收藏  举报

导航