[Update] Spring Developers guide to Starting with Pivotal Cloud Cache and Gemfire

The following article is an update to an older post which was based on older versions of Spring/Spring Data Geode.  In this article, you will learn how to complete the following steps.

  • Create a local GemFire Server for testing.
  • Create a cache client application.
  • Create a Pivotal Cloud Cache service instance in Pivotal Cloud Foundry (PCF)
  • Deploy client application to PCF

The complete code is on Github.

Cache Server for local development

Use Spring Boot

Alternatively, you can use a docker image to achieve the same result.

Running this command will drop you into a GFSH shell that you can use to start the locator, server and create some regions.

Simple Client

Next, we will create a simple client also using Spring Boot which will do most of the heavy lifting for us.

  • This class is a SpringBootApplication
  • This application requires a client cache
  • Automatically define client regions based on Repositories found on the classpath
  • Make Repositories found, GemFire repositories
  • Enable PDX Serialization.
  • We then can establish a typical Spring Data Repository.

Lastly, we need to tell Spring where to find the cache locator by adding a property to application.properties. The correct host and port should be visible in your CacheServer startup log.

When you run the application, you should see output indicating data was placed in the cache and subsequently retrieved from the cache.

Using Pivotal Cloud Cache (PCC)

PCC is a cloud-based cache that can be deployed to Cloud Foundry. Assuming your PCF instance has PCC already installed you can efficiently utilize the cf command line to create and maintain your cache.

Create the cache

Verify that PCC is available.

Look for p-cloudcache. If it isn’t available, you will need to work with your cloud operator to have them install the tile.

Create the service

Create a service instance of the cloud cache called pcc This may take some time to complete so you can monitor its progress with

Service Key

Once the instance creation succeeds, we will need a service key. The service key will provide the required credentials for working with the cache. By default, you will have two users one with developer access and one with operator access. This information will also be exposed via VCAP_SERVICES to allow applications in other deployed containers to connect.

Create Regions Using GFSH

Create a Region in PCC to hold the data. Use the locator URL and GFSH operator credentials from above.

Load the GFSH utility included with the GemFire distribution.

Connect to the cache to create the region.

In a previous post I talked about manually creating the ClientCache bean to customize it. This procedure is no longer necessary with Spring Boot Data Gemfire. When pushing an app to cloud foundry as long as it is bound to PCC the credentials will automatically be loaded from VCAP_SERVICES.

If you are running your application outside of PCC you can manually set this information via spring properties.

Create a PCF manifest to bind the cache to your application

Push your app as normal

Customizing Region and Cache Configuration.

With Spring Boot Data G the Region and Client Cache are automatically configured. Sometimes the settings need adjustments. In the past version of this post, I advocated just creating these beans manually. In Spring Boot Data G there is an interface that can be used to customize these beans before their creation.

You may also like...

1 Response

  1. April 10, 2019

    […] This article has been updated. Latest content is here […]