javagemfirein-memory-data-gridbigdata

GemFire put on server Region using JAVA


How can I connect to GemFire cluster with java code , get regions and put some values into this regions from client.


Solution

  • There are several examples of what you're trying to achieve within the Official User Guide, specifically in Client/Server Example Configurations. A minimalist example below.

    server-cache.xml

    <cache>
        <cache-server/>
        <region name="TEST">
            <region-attributes refid="REPLICATE"/>
        </region>
    </cache>
    

    client-cache.xml

    <client-cache>
        <pool name="default">
            <locator host="localhost" port="10334"/>
        </pool>
        <region name="TEST" refid="PROXY"/>
    </client-cache>
    

    ClientApp.java

    public static void main(String[] args) throws Exception {
        ClientCache cache = new ClientCacheFactory().set("cache-xml-file", "client-cache.xml").set("log-level", "config").create();
        Region region = cache.getRegion("TEST");
        region.put("key1", new MyPojo("attribute1", "attribute2"));
        cache.close();
        System.exit(0);
    }
    

    You might want to check the spring-data-gemfire project, and get rid of all the boilerplate :-). Cheers.