Skip to content

spring-cloud-services-samples/traveler

CircleCI

Circuit Breaker Dashboard sample

Company and Agency are example applications demonstrating the use of Circuit Breaker Dashboard for Pivotal Cloud Foundry. (For information on the Circuit Breaker Dashboard product, please see the documentation.)

Building and Deploying

  1. Build the two projects from the root (traveler) directory. If using Maven, run:

    $ mvn package

    If using Gradle, run ./gradlew build (OS X, Linux) or gradlew.bat build (Windows).

    $ ./gradlew build
  2. Run the deployment script (if you used Maven, scripts/deploy_mvn.sh or scripts/deploy_mvn.bat; if you used Gradle, scripts/deploy_gradle.sh or scripts/deploy_gradle.bat).

    $ ./scripts/deploy_gradle.sh

    The script will create Circuit Breaker Dashboard and Service Registry service instances and then push the applications and bind them to the appropriate services.

  3. When the script has finished, set the TRUST_CERTS environment variable to the API endpoint of your Elastic Runtime instance (as in api.example.com), then restage the applications so that the changes will take effect. Setting TRUST_CERTS causes Spring Cloud Services to add the the SSL certificate at the specfied API endpoint to the JVM’s truststore, so that the client application can communicate with a Service Registry service instance even if your Elastic Runtime instance is using a self-signed SSL certificate (see the Service Registry documentation).

    $ cf set-env company TRUST_CERTS api.wise.com
    Setting env variable 'TRUST_CERTS' to 'api.wise.com' for app company in org myorg / space development as user...
    OK
    TIP: Use 'cf restage' to ensure your env variable changes take effect
    $ cf restage company
    $ cf set-env agency TRUST_CERTS api.wise.com
    Setting env variable 'TRUST_CERTS' to 'api.wise.com' for app agency in org myorg / space development as user...
    OK
    TIP: Use 'cf restage' to ensure your env variable changes take effect
    $ cf restage agency
    Note

    By default, the Spring Cloud Services Starters for Service Registry causes all application endpoints to be secured by HTTP Basic authentication. For more information or if you wish to disable this, see the documentation. (HTTP Basic authentication is disabled in these sample applications.)

Trying It Out

  1. Visit [ROUTE], where [ROUTE] is the route bound to the Agency application. In the Agency application, the getGuide() method on the TravelAgent class will use the Service Registry to look up the Company application and get a guide name, which will be randomly selected from a pool of three.

    link:docs/images/guide.png

    You can simulate load on the Agency application by using curl.

    $ while true; do curl https://agency.wise.com; done
  2. To see the circuit breaker in action, stop the Company application. (You can do this either from Pivotal Cloud Foundry Apps Manager or using the cf Command Line Interface tool.)

    $ cf stop company
    Stopping app company in org myorg / space development as user...
    OK

    The Agency application’s calls to the Company application will begin failing. Once the failure rate reaches a threshold, the Circuit Breaker Dashboard will trip the getGuide() breaker. The calls will fall back to the Agency application’s own getBackupGuide() method and return a static backup guide name while the circuit is open.

    link:docs/images/backup-guide.png
  3. Check the dashboard to see the breaker status. Alongside the graph, the dashboard shows the status of calls made to getGuide() in the last 10 seconds. Call counts are color-coded.

    link:docs/images/open-circuit.png
  4. Start the Company application again (using either Apps Manager or the cf CLI).

    $ cf start company
    Starting app company in org myorg / space development as user...
    
    0 of 1 instances running, 1 starting
    0 of 1 instances running, 1 starting
    1 of 1 instances running
    
    App started

    After the Company application has started and re-registered with the Service Registry instance and after the registration has trickled down to the Agency application, the Circuit Breaker Dashboard will close the getGuide() circuit.

    link:docs/images/closed-circuit.png

    You should again see calls to the Company application going through.

For more information about the Circuit Breaker Dashboard and its use in a client application, see the Circuit Breaker Dashboard documentation.

About

Sample applications demonstrating use of Circuit Breaker Dashboard for Pivotal Cloud Foundry.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published