/fortune-teller

Yet another great Spring Cloud sample app...

Primary LanguageJava

Fortune Teller

Fortune Teller is a very basic application composed of two services:

  1. Fortune Service - serves up random Chinese fortune cookie fortunes

  2. Fortune UI - presents a UI that consumes the fortune service

It leverages libraries and services from Spring Cloud and Netflix OSS to compose the system.

Fortune Teller is deployable to any Cloud Foundry environment utilizing the service components that have been packaged with the project. However, it is most easily deployed to Pivotal Cloud Foundry environments that have installed the Spring Cloud Services package.

Building

  1. Using Maven, build and package the application:

    $ mvn package

    Maven will automatically download all of Fortune Teller's dependencies. This may take a few moments.

Deploying to Pivotal Cloud Foundry with Spring Cloud Services

  1. Run scripts/create_services_pcf.sh to create the services that you need:

    $ ./scripts/create_services_pcf.sh
    Creating service fortune-db in org microservices / space fortune-teller as admin...
    OK
    Creating service config-service in org microservices / space fortune-teller as admin...
    OK
    Creating service service-registry in org microservices / space fortune-teller as admin...
    OK
    Creating service circuit-breaker in org microservices / space fortune-teller as admin...
    OK
  2. In the Pivotal Cloud Foundry Apps Manager console, click on the Manage link for the Config Server. Once the service is initialized and the web form appears, paste the URL of this repository (https://github.com/spring-cloud-samples/fortune-teller) into the Git URI field and "configuration" into the Search Paths field. Then click Submit.

  3. Also click on the Manage links for the Service Registry and Circuit Breaker. Make sure the services are finished initializing before you proceed.

  4. Edit the manifest-pcf.yml file to specify the Cloud Foundry target the apps are being pushed to, replacing the URL in CF_TARGET: https://api.cf.deepsouthcloud.com with the API endpoint for your Cloud Foundry deployment.

  5. Push the microservices:

    $ cf push -f manifest-pcf.yml

    This will push the fortunes service and the ui application and bind all of the services.

Deploying to Pivotal Web Services (or other Cloud Foundry environments)

  1. Push the Spring Cloud services:

    $ cf push -f manifest-services.yml

    This will push a Spring Cloud Config Server, a Eureka server, and a Hystrix Dashboard, all with random routes.

  2. Edit scripts/create_services.sh to add the random routes that were generated for you:

    cf cups config-service -p '{"uri":"http://config-server-fluxional-suttee.cfapps.io"}'
    cf cups service-registry -p '{"uri":"http://eureka-unprevalent-toper.cfapps.io"}'
    cf cs elephantsql turtle fortunes-db
  3. Run scripts/create_services.sh to create the services that you need:

    $ scripts/create_services.sh
    Creating user provided service config-service in org platform-eng / space nfjs-workshop as mstine@pivotal.io...
    OK
    Creating user provided service service-registry in org platform-eng / space nfjs-workshop as mstine@pivotal.io...
    OK
    Creating service fortunes-db in org platform-eng / space nfjs-workshop as mstine@pivotal.io...
    OK
  4. Push the microservices:

    $ cf push -f manifest-apps.yml

    This will push the fortunes service and the ui application.

Testing the Application

  1. In a browser, access the fortunes-ui application at the route that was created for you:

    fortunes 1

  2. Now, in another browser tab, access the Hystrix Dashboard at the route that was created for you. Enter the route for the UI application and click the ``Monitor Stream.''

    Note
    On Pivotal Cloud Foundry, you can access a pre-configured Hystrix Dashboard by clicking on the Manage link for Circuit Breaker Dashboard. You will NOT need to paste in the route.

    fortunes 2

  3. Access the fortunes-ui and show that the circuit breaker is registering successful requests.

    fortunes 3

  4. Stop the fortunes application:

    $ cf stop fortunes
  5. Access the fortunes-ui and see that the ``fallback fortune'' is being returned.

    fortunes 4

  6. Access the fortunes-ui and show that the circuit breaker is registering short-circuited requests.

    fortunes 5

  7. Start the fortunes application:

    $ cf start fortunes
  8. Continue to access the fortunes-ui and watch the dashboard. After the fortunes service has re-registered with Eureka and the fortunes-ui load balancer caches are refreshed, you will see the circuit breaker recover. You should then start getting random fortunes again!