Giter Club home page Giter Club logo

cf-gemfire-connector-examples's Introduction

cf-gemfire-connector-examples

Example applications that use the GemFire on Pivotal Cloud Foundry service.

For an application to connect to a provisioned GemFire cluster in Cloud Foundry, it has to create a GemFire ClientCache which connects to the GemFire locators. The application also has to provide an implementation of AuthInitialize which will send the client credentials to the server. The credentials and the locator information is present in the VCAP_SERVICES environment variable. This repository has five examples of how these environment variables can be parsed.

There are 5 example applications in this repository:

  • Java main application
  • Java main application using spring cloud connectors
  • Spring boot application using spring cloud connectors
  • Spring boot application using spring cloud connectors with custom GemFire client configuration
  • Spring boot application using spring cloud connectors and GemfireRepository

Following are the common steps for all examples to create a GemFire Service and create a Region:

  • create a GemFire service instance named "service0" cf create-service p-gemfire GemFireServicePlan1 service0
  • install the gemfire plugin for the cf command
  • create a region named "test"
    • connect gfsh to the service instance cf show-gfsh service0 will print the command to run in gfsh to connect to the cluster (install GemFire cf plugin from Pivotal Network
    • gfsh>create region --name=test --type=PARTITION will create a region named "test"

Clone this repo, then build all examples with:

$ ./gradlew build

To deploy individual application to cloudfoundry:

  1. cd to the project dir
  2. $ cf push

Java main application

application name: java-app

This application uses jackson to parse the environment variable in the EnvParser class. ClientAuthInitialize is an implementation of AuthInitialize that is used for handling client authenticatin. The main class, MyJavaApplication creates a ClientCache that uses the ClientAuthInitialize for authentication and uses EnvParser to get the locator information.

Java main application using spring cloud connector

application name: java-app-spring-cloud

To use the spring connector, your application does not have to be spring application. Just specify spring-cloud-core and spring-cloud-gemfire-cloudfoundry-connector as your project dependencies and let the connector parse the VCAP_SERVICES environment variable for you. In the application you can get ServiceInfo like so:

    CloudFactory cloudFactory = new CloudFactory();
    Cloud cloud = cloudFactory.getCloud();
    GemfireServiceInfo myService = (GemfireServiceInfo) cloud.getServiceInfo("service0");

You will still need to provide an implementation of AuthInitialize like in the previous example. Please refer to the application.

Spring Application

application name: spring-app

If you use Spring, you can just Autowire ClientCache into your application.

Spring Application with custom GemFire client configuration

application name: spring-app-client-config

If the ClientCache requires additional configuration then the Cache needs to be explictly created using a ServiceConnectorConfig. The application needs to create a CacheClient bean using the CloudFactory.

Spring Application using Spring GemfireRepository

application name: gemfire-spring-pizza-store

This is a GemFire Spring client application which uses GemfireRepository class to access a GemFire cluster. The application assumes that a GemFire cluster exists and contains a region named Pizza. Please see instructions above on how to create a GemFire cluster. This application has a endpoint /healthcheck, which inserts a single element and reads it back.

cf-gemfire-connector-examples's People

Contributors

cdavisafc avatar pulkit-chandra avatar michaelabon avatar petahhh avatar idoru avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.