1

I am working on a project that has a requirement of Pivotal GemFire. I am unable to find a proper tutorial about how to configure gemFire with Spring Boot.

I have created a partitioned Region and I want to configure Locators as well, but I need only server-side configuration as client is handled by someone else.

I am totally new to Pivotal GemFire and really confused. I have tried creating a cache.xml but then somehow a cache.out.xml gets created and there are many issues.

John Blum
  • 7,381
  • 1
  • 20
  • 30
  • Also i cant use gfsh commands, I need to have properties files or hard coded. –  Jan 13 '17 at 06:42

2 Answers2

2

@Priyanka-

Best place to start is with the Guides on spring.io. Specifically, have a look at...

"Accessing Data with GemFire"

There is also...

"Cache Data with GemFire", and...

"Accessing GemFire Data with REST"

However, these guides focus mostly on "client-side" application concerns, "data access" (over REST), "caching", etc.

Still, you can use Spring Data GemFire (in a Spring Boot application even) to configure a GemFire Server. I have many examples of this. One in particular...

"Spring Boot GemFire Server Example"

This example demonstrates how to bootstrap a Spring Boot application as a GemFire Server (technically, a peer node in the cluster). Additionally, the GemFire properties are specified Spring config and can use Spring's normal conventions (property placeholders, SpEL expression) to configure these properties, like so...

https://github.com/jxblum/spring-boot-gemfire-server-example/blob/master/src/main/java/org/example/SpringBootGemFireServer.java#L59-L84

This particular configuration makes the GemFire Server a "GemFire Manager", possibly with an embedded "Locator" (indicated by the start-locator GemFie property, not to be confused with the "locators" GemFire property which allows our node to join and "existing" cluster) as well as a GemFire CacheServer to serve GemFire cache clients (with a ClientCache).

This example creates a "Factorials" Region, with a CacheLoader (definition here) to populate the "Factorials" Region on cache misses.

Since this example starts an embedded GemFire Manager in the Spring Boot GemFire Server application process, you can even connect to it using Gfsh, like so...

gfsh> connect --jmx-manager=localhost[1099]

Then you can run "gets" on the "Factorial" Region to see it compute factorials of the numeric keys you give it.

To see more advanced configuration, have a look at my other repos, in particular the Contacts Application RI (here).

Hope this helps!

-John

John Blum
  • 7,381
  • 1
  • 20
  • 30
1

Well, I had the same problem, let me share with you what worked for me, in this case I'm using Spring Boot and Pivotal GemFire as cache client.

  1. Install and run GemFire
  2. Read the 15 minutes quick start guide
  3. Create a locator(let's call it locator1) and a server(server1) and a region(region1)
  4. Go to the folder where you started the 'Gee Fish'(gfsh) and then go to the locator's folder and open the log file, in that file you can get the port your locator is using.

Now let's see the Spring boot side:

  1. In you Application with the main method add the @EnablegemFireCaching annotation
  2. In the method(wherever it is) you want to cache, add the @Cacheable("region1") annotation.
  3. Now let's create a configuration file for the caching:

    //this is my working class

    @Configuration public class CacheConfiguration {

    @Bean
    ClientCacheFactoryBean gemfireCacheClient() {
        return new ClientCacheFactoryBean();
    }
    
    @Bean(name = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME)
    PoolFactoryBean gemfirePool() {
    
        PoolFactoryBean gemfirePool = new PoolFactoryBean();
    
        gemfirePool.addLocators(Collections.singletonList(new ConnectionEndpoint("localhost", HERE_GOES_THE_PORT_NUMBER_FROM_STEP_4)));
        gemfirePool.setName(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
        gemfirePool.setKeepAlive(false);
        gemfirePool.setPingInterval(TimeUnit.SECONDS.toMillis(5));
        gemfirePool.setRetryAttempts(1);
        gemfirePool.setSubscriptionEnabled(true);
        gemfirePool.setThreadLocalConnections(false);
    
        return gemfirePool;
    }
    
    @Bean
    ClientRegionFactoryBean<Long, Long> getRegion(ClientCache gemfireCache, Pool gemfirePool) {
        ClientRegionFactoryBean<Long, Long> region = new ClientRegionFactoryBean<>();
        region.setName("region1");
        region.setLookupEnabled(true);
        region.setCache(gemfireCache);
        region.setPool(gemfirePool);
        region.setShortcut(ClientRegionShortcut.PROXY);
    
        return region;
    }
    

    That's all!, also do not forget to serialize(implements Serializable) the class is being cached(The class your cached method is returning)

Eduardo
  • 2,070
  • 21
  • 26