Cloud Native Applications
for
Cloud Foundry using Spring Cloud
Workshop
Corneil du Plessis
About Me
• Working as Programmer since 1985
• Smallest to very large systems.
• Cobol, Fortan, Pascal, Algol, C/C++, Java, JavaScript,
Groovy, Python, Scala, Kotlin and more.
• Scientific instrumentation, Sports event
management, Mining, Banking, Treasury and
Insurance.
• Software Architect (with a preference for coding)
@corneil
Agenda
• Background
• Cloud Foundry command-line
• Your first Cloud Foundry application
• Connecting to database
• Connecting to message queues
• Scaling your application
• Application Discovery
Background
• What is Cloud Foundry?
• Application Runtime
• Container Runtime
• Who provides Cloud Foundry
Application Runtime?
• Atos
• Cloud.gov
• Fujitsu Cloud Service K5
• Huawei FusionStage
• IBM Bluemix
• Pivotal Cloud Foundry
• SAP Cloud Platform
• Suse Cloud Application Platform
• Swisscom Application Cloud
• Who uses Cloud Foundry?
• Governments
• Banks
• Insurance
• Telecomms
• Airlines
• Retail (Online)
• Retail (Bricks and mortar)
• Aerospace
https://www.cloudfoundry.org/case-studies/
Cloud Foundry Application Runtime
Terminology
• CAT
• BOSCH
• Deigo
• Services
• Application Manifest
• Organisation
• Space
• Buildpack
Cloud Foundry Buildpacks
• Binary
• Go
• Java
• .Net Core
• Node.js
• PHP
• Python
• Ruby
• Staticfile
• NGIX
• HWC (Hosted Web Core)
• Community
• TomEE
• WebSphere Liberty
• Jetty
• Erlang
• Haskell
• Swift
The 12 Factors
https://12factor.net
1. One Codebase in revision control
2. Dependencies must be explicit
3. Config in environment
4. Backing services as attached resources
5. Build, release, run as separate stages
6. One or more stateless processes
7. Export services via port binding
8. Concurrency in Process over threads
9. Disposable with quick startup and graceful shutdown.
10. Keep development/test/production in parity
11. Treat logs as event streams
12. Admin/management tasks as one-off processes
Cloud Foundry command-line
• cf login
• cf push
• cf marketplace
• cf create-service
• cf bind-service
• cf scale
• cf restart
• Many Plugins
• Authenticate Operator
• Deploy Application
• List services
• Create / Provision a service
• Bind service to application
• Scale application
• Restart the application
Visit Workshop Page
https://github.com/corneil/cf-demo
Your first Application
View Logs and Invoke
Connecting to Database
• Create Spring Data Repository.
• Update EventServiceImpl to use the repository.
• Add @Configuration extending AbstractCloudConfig to
provide @Bean of type DataSource.
• Add @Transactional to Controller to preserve the Stream
Provision PostgreSQL and Deploy
Connecting to Message Queues
• Create @Bean for RabbitMQ ConnectionFactory by extending
AbstractCloudConfig.
• Create @Bean for Queue.
• Implement listener method with @RabbitListener that saves
Event using repository.
• Modify createEvent to send event to message queue using
AmqpTemplate.
Provision RabbitMQ and Deploy
Scaling your application
Application Discovery
• @EnableDiscoveryClient
• Access resources:
• https://<target-name>/
• OpenFeign Client
Cloud Foundry Plugins
• Maven Push
https://github.com/fitzoh/maven-push-plugin
• Java
https://github.com/SAP/cf-cli-java-plugin
• Spring Cloud Services
https://github.com/pivotal-cf/spring-cloud-services-cli-plugin
• Spring Cloud Data Flow for PCF
https://github.com/pivotal-cf/spring-cloud-dataflow-for-pcf-cli-plugin
• Zero downtime deployments
https://github.com/bluemixgaragelondon/cf-blue-green-deploy
Finally
• Code: https://github.com/corneil/cf-demo
• Resources:
• https://docs.cloudfoundry.org/buildpacks/java/getting-started-deploying-apps/gsg-spring.html
• https://docs.cloudfoundry.org/buildpacks/java/configuring-service-connections/spring-service-bindings.html
• https://docs.spring.io/spring-cloud/docs/current/api/org/springframework/cloud/config/java/AbstractCloudConfig.html

Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop

  • 1.
    Cloud Native Applications for CloudFoundry using Spring Cloud Workshop Corneil du Plessis
  • 2.
    About Me • Workingas Programmer since 1985 • Smallest to very large systems. • Cobol, Fortan, Pascal, Algol, C/C++, Java, JavaScript, Groovy, Python, Scala, Kotlin and more. • Scientific instrumentation, Sports event management, Mining, Banking, Treasury and Insurance. • Software Architect (with a preference for coding) @corneil
  • 3.
    Agenda • Background • CloudFoundry command-line • Your first Cloud Foundry application • Connecting to database • Connecting to message queues • Scaling your application • Application Discovery
  • 4.
    Background • What isCloud Foundry? • Application Runtime • Container Runtime • Who provides Cloud Foundry Application Runtime? • Atos • Cloud.gov • Fujitsu Cloud Service K5 • Huawei FusionStage • IBM Bluemix • Pivotal Cloud Foundry • SAP Cloud Platform • Suse Cloud Application Platform • Swisscom Application Cloud • Who uses Cloud Foundry? • Governments • Banks • Insurance • Telecomms • Airlines • Retail (Online) • Retail (Bricks and mortar) • Aerospace https://www.cloudfoundry.org/case-studies/
  • 5.
  • 6.
    Terminology • CAT • BOSCH •Deigo • Services • Application Manifest • Organisation • Space • Buildpack
  • 7.
    Cloud Foundry Buildpacks •Binary • Go • Java • .Net Core • Node.js • PHP • Python • Ruby • Staticfile • NGIX • HWC (Hosted Web Core) • Community • TomEE • WebSphere Liberty • Jetty • Erlang • Haskell • Swift
  • 8.
    The 12 Factors https://12factor.net 1.One Codebase in revision control 2. Dependencies must be explicit 3. Config in environment 4. Backing services as attached resources 5. Build, release, run as separate stages 6. One or more stateless processes 7. Export services via port binding 8. Concurrency in Process over threads 9. Disposable with quick startup and graceful shutdown. 10. Keep development/test/production in parity 11. Treat logs as event streams 12. Admin/management tasks as one-off processes
  • 9.
    Cloud Foundry command-line •cf login • cf push • cf marketplace • cf create-service • cf bind-service • cf scale • cf restart • Many Plugins • Authenticate Operator • Deploy Application • List services • Create / Provision a service • Bind service to application • Scale application • Restart the application
  • 10.
  • 11.
  • 12.
  • 13.
    Connecting to Database •Create Spring Data Repository. • Update EventServiceImpl to use the repository. • Add @Configuration extending AbstractCloudConfig to provide @Bean of type DataSource. • Add @Transactional to Controller to preserve the Stream
  • 14.
  • 15.
    Connecting to MessageQueues • Create @Bean for RabbitMQ ConnectionFactory by extending AbstractCloudConfig. • Create @Bean for Queue. • Implement listener method with @RabbitListener that saves Event using repository. • Modify createEvent to send event to message queue using AmqpTemplate.
  • 16.
  • 17.
  • 18.
    Application Discovery • @EnableDiscoveryClient •Access resources: • https://<target-name>/ • OpenFeign Client
  • 19.
    Cloud Foundry Plugins •Maven Push https://github.com/fitzoh/maven-push-plugin • Java https://github.com/SAP/cf-cli-java-plugin • Spring Cloud Services https://github.com/pivotal-cf/spring-cloud-services-cli-plugin • Spring Cloud Data Flow for PCF https://github.com/pivotal-cf/spring-cloud-dataflow-for-pcf-cli-plugin • Zero downtime deployments https://github.com/bluemixgaragelondon/cf-blue-green-deploy
  • 20.
    Finally • Code: https://github.com/corneil/cf-demo •Resources: • https://docs.cloudfoundry.org/buildpacks/java/getting-started-deploying-apps/gsg-spring.html • https://docs.cloudfoundry.org/buildpacks/java/configuring-service-connections/spring-service-bindings.html • https://docs.spring.io/spring-cloud/docs/current/api/org/springframework/cloud/config/java/AbstractCloudConfig.html