GithubHelp home page GithubHelp logo

isabella232 / redisforpcf-java-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redislabs-solution-architects/redisforpcf-java-example

0.0 0.0 0.0 11 KB

License: MIT License

Java 100.00%

redisforpcf-java-example's Introduction

Redis Enterprise for PCF Java Sample App

This project demonstrates how to use Redis for PCF to create a Redis Enterprise service instance and connect to it without using Spring Cloud Connectors. If you are building a Spring Boot app you may wish to investigate that approach here: https://cloud.spring.io/spring-cloud-connectors/

Cloud Foundry sets certain configuration values such as service dependency connection information in an environment variable called VCAP_SERVICES inside the container where your app is running. This sample app parses VCAP_SERVICES to pull out the necessary connection information from there and then connects to Redis if it can.

This app needs to be pushed to Cloud Foundry. It won't work on your local machine.

How to deploy

Create the Redis Enterprise service instance

First, you need to create a Redis Enterprise service instance. You'll need to determine what the Redis Enterprise service is called in your PCF installation's service marketplace. To do this, do "cf marketplace". It's likely that you'll encounter one or more of the following three values:

  • redislabs: this is the Redis Enterprise service provided by Redis Labs to people using Pivotal Web Services. It provide HA, durable, and geo-redundant Redis services.
  • rediscloud: this is the Redis service provided by Redis Labs to people using Pivotal Web Services.
  • p.redis: this is the new on-demand-brokered Redis for PCF service (provided by pivotal). This service provides a single shard non-HA Redis service.

Once you've determined the name of the service and the name of the plan, create an instance. For example, do
cf create-service redislabs small-redis my-sample-redis
or
cf create-service redislabs small-redis my-sample-redis

Clone, build, and push

Clone this repo by doing
git clone https://github.com/Redislabs-Solution-Architects/RedisForPCF-Java-Example.git

Build the project by doing
mvn package

Push to PCF by doing
cf push

Try app in unbound state

If the above steps were successful, the app will be running on Cloud Foundry but the Redis service instance you created in the first step is not yet bound to the app. In this state, you can try the app's endpoints (detailed below) to see how things work in this state. As you have not bound Redis, you will not be able to see any service credentials or write any keys to the store.

Bind the service instance

Binding a service instance to an app tells that app how to connect to the service instance. To bind your service instance to your app (assuming you used the same app and service instance names; if not, change as appropriate), do
cf bind-service redisexample my-sample-redis.
Once this is done, restart your app. This is necessary because changes in the container environment (such as the addition of the Redis service instance connection credentials) are not reflected inside the Java process environment until it is restarted.
cf restart redisexample

Try app in bound state

Now you can test out the app and ensure that it can retrieve connection info, connect to your Redis service instance, and write/read keys.

Endpoints to try

/

If you visit https://redisexample.yourappsdomain.example.com/ you should see information about your Redis service instance. This method does not attempt to connect to the Redis service instance. If no service is bound, you will see an error message.

/set?kn=KEYNAME&kv=KEYVALUE

The method at https://redisexample.yourappsdomain.example.com/set will set a key in your bound Redis service instance. Make a GET request; it takes two params supplied on the query string. kn should be the name of the key you want to set and kv should be the value of the key you want to set. On success, it returns a success message. If no service is bound, you will see an error message.

/get?kn=KEYNAME

The method at https://redisexample.yourappsdomain.example.com/get will get a key in your bound Redis service instance. Make a GET request; it takes one param supplied on the query string. kn should be the name of the key you want to get the value for. On success, the value of kn will be returned. If no service is bound, you will see an error message.

redisforpcf-java-example's People

Contributors

bjbredis avatar colrich 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.