Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a
Creative Commons Attr...
Próxima SlideShare
Cargando en…5
×

Consuming Data Services with Spring Apps on Cloud Foundry

698 visualizaciones

Publicado el

SpringOne Platform 2016
Speaker: Scott Frederick; Sr. Software Engineer, Pivotal

Applications running on Cloud Foundry often need to connect to data services such as relational databases, document and data structure stores, and messaging services. Spring Cloud Connectors, Spring Boot and Cloud Foundry make it easy to connect Java and Spring applications to these types of data sources. Spring Boot and the Cloud Foundry Java Buildpack provide auto-configuration capabilities that make it possible to connect to data services with no application code changes for simple use cases, yet back away gracefully when custom configuration of connections is required.

This talk will cover how these auto-configuration mechanisms work, their limitations, and how to explicitly configure connections when the need arises.

Publicado en: Tecnología
0 comentarios
2 recomendaciones
Estadísticas
Notas
  • Sé el primero en comentar

Sin descargas
Visualizaciones
Visualizaciones totales
698
En SlideShare
0
De insertados
0
Número de insertados
12
Acciones
Compartido
0
Descargas
15
Comentarios
0
Recomendaciones
2
Insertados 0
No insertados

No hay notas en la diapositiva.

Consuming Data Services with Spring Apps on Cloud Foundry

  1. 1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consuming Data Services with Spring Apps on Cloud Foundry Scott Frederick @scottyfred
  2. 2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Apps and Services 2 $ cf push my-app $ cf create p-mysql 100mb my-db $ cf bind my-app my-db
  3. 3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Layers of Data Access 3 application Spring Data connection library / driver configure connection
 parameters here
  4. 4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s a “data service”? Resources provisioned on demand • Managed services instances are provisioned by service brokers • User-provided services instances can be used to expose off-platform resources to applications running on the platform Once provisioned, service instances can be exposed to applications on the platform Data services provide persistence and messaging to applications 4
  5. 5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ "VCAP_SERVICES": { "p-mysql": [{ "label": "p-mysql", "name": "customer-db", "plan": "100mb", "tags": ["mysql","relational"] "credentials": { "jdbcUrl": "jdbc:mysql://192.168.1.149:3306/ cf_231f410b_235f_461e_a7f6_bddf3469fa93?user=khuTGcRGBsvIWUjB u0026password=aFwkW2UTMhHPcUsR", "uri": "mysql:// khuTGcRGBsvIWUjB:aFwkW2UTMhHPcUsR@192.168.1.149:3306/ cf_231f410b_235f_461e_a7f6_bddf3469fa93?reconnect=true" } }] Application Environment 6
  7. 7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7 http://cloud.spring.io/spring-cloud-connectors
  8. 8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Supported Services • Relational Databases • MySQL • PostgreSQL • Oracle • DB2 • SQLServer • MongoDB • Redis • RabbitMQ • SMTP e-mail 8 http://cloud.spring.io/spring-cloud-connectors
  9. 9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo 9
  10. 10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java Buildpack Auto Re-configuration Adds an “auto-reconfiguration” jar to the application’s classpath on deployment • Implements a BeanPostProcessor that inspects AppContext • Detects beans of known types supported by Connectors • Replaces existing beans in the AppContext with Connectors-created beans Automatically enabled when core Spring jars are detected in the deployed app archive 10 Spring Cloud Connectors Java Buildpack auto-reconfigurationJava Buildpack application
  11. 11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java Buildpack Auto Re-configuration Limitations • Supports only one bean of a service type (e.g. relational database) • Supports RDBMD, MongoDB, Redis, and RabbitMQ only • Connection details can’t be customized Automatically disabled when Connectors classes are detected in the app Can be manually disabled via an environment variable 11 $ cf set-env customer-app
 JBP_CONFIG_SPRING_AUTO_RECONFIGURATION 
 '{enabled: false}'
  12. 12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo 12
  13. 13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Boot Auto Configuration Spring Boot provides auto configuration via Connectors • Creates connection beans for any service type known to Connectors 
 (core or extensions) • Takes precedence over other Spring Data auto configuration Cloud Connectors starter includes classes necessary to enable this auto configuration • Disables Java Buildpack auto re-configuration 13 Spring Cloud Connectors Spring Boot auto configuration application
  14. 14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ spring.cloud.enabled=false Limitations • Supports only one bean of a service type (e.g. relational database) • Connection details can’t be customized Automatically disabled when the Connectors “Cloud” class is present in the app context Can be manually disabled via a Spring Boot property Spring Boot Auto Configuration 14
  15. 15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connectors Manual Configuration Gives full control over the connection configuration with a small amount of code Allows customization of connection parameters and connection pool configuration Supports configuration of multiple services of the same type 16 Spring Cloud Connectors application
  17. 17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Configuration with Multiple Services 17 @Configuration public class DatabaseConfig extends AbstractCloudConfig { @Bean public DataSource customerDataSource() { return connectionFactory().dataSource(“customer-db”); } @Bean public DataSource orderDataSource() { return connectionFactory().dataSource(“order-db”); } }
  18. 18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @Configuration @Profile("default") public class LocalDatabaseConfig { @Bean public DataSource dataSource() { return DataSourceBuilder.create().build(); } } @Configuration @Profiles(“cloud”) public class CloudDatabaseConfig extends AbstractCloudConfig { @Bean public DataSource dataSource() { return connectionFactory().dataSource(); } } Profiles for local testing 18
  19. 19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ A “cloud” property source is added to Spring Boot properties These properties can be used to explicitly configure other Spring Boot properties Limitations • Supports only one bean of a service type (e.g. relational database) • Properties vary by service offering • Either the service type (e.g. “mysql”) or name (e.g. “customer-db”)
 must be used in property placeholder spring.datasource.url: ${cloud.services.mysql.connection.jdbcurl} spring.datasource.username: ${cloud.services.mysql.connection.username} spring.datasource.password: ${cloud.services.mysql.connection.password} One More Option 19
  20. 20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Binding to Data Services with Spring Boot in Cloud Foundry https://spring.io/blog/2015/04/27/binding-to-data-services-with-spring-boot-in-cloud-foundry Demo app https://github.com/scottfrederick/data-binding Consuming other types of data services https://github.com/cloudfoundry-samples/spring-music Further Reading 20
  21. 21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learn More. Stay Connected. Introduction to Spring Data - Greg Turnquist What's New in Spring Data? - Mark Paluch, Christoph Strobl Advanced Spring Data REST - Oliver Gierke @springcentral spring.io/blog @pivotal pivotal.io/blog @pivotalcf http://engineering.pivotal.io

×