Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Eclipse microprofile config and OSGi config admin - E Jiang

210 views

Published on

OSGi Community Event 2017 Presentation by Emily Jiang [IBM]

Eclipse MicroProfile Config defines a Java programming model for microservices. It offers the capability of configuring microservices without repacking the microservices; microservices reacting differently based on the deployment environment; dynamic configuration feeding into the microservices without restarting the microservices. OSGi Config Admin exists for many years and offers an efficient configuration model to OSGi applications. MicroPorfile Config can work well in OSGi applications. It doesn't contradict but instead compliments Config Admin. Come to this session to find out the common and different features between the two technologies, as well as the possibility of integrating Eclipse MicroProfile Config to OSGi applications.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Eclipse microprofile config and OSGi config admin - E Jiang

  1. 1. © 2017 IBM Corporation EclipseCon Europe 2017 Eclipse MicroProfile Config and OSGi Config Admin Emily Jiang – MicroProfile Development Lead @emilyfhjiang 1
  2. 2. © 2017 IBM Corporation  What are Microservices? – Small concise service – small piece of SOA – Easy to maintain – Easy to release – Loosely coupled a number of them to form a system  Microservice best practice – Configurable – Fault tolerance – Monitoring – Secure – Working well in the cloud  How to build it the right way? – Use Eclipse MicroProfile 2 CDI 1.2
  3. 3. © 2017 IBM Corporation What is Eclipse MicroProfile? Eclipse MicroProfile is an open-source community specification for Cloud Native Java microservices A community of individuals, organizations, and vendors collaborating within an open source (Eclipse) project to bring microservices to the Enterprise Java community 3
  4. 4. © 2017 IBM Corporation Community - individuals, organizations, vendors And Growing ... 4
  5. 5. © 2017 IBM Corporation  Why Eclipse MicroProfile? – Microservice portable among application servers – No vendor locking unlike Spring – Fast innovating – Frequent release cycle 5 CDI 1.2
  6. 6. © 2017 IBM Corporation Accelerating Adoption of Microservices 6 Time 8 ? MicroProfile 1.0 CDI 1.2 JAX-RS 2.0 JSON-P 1.0 MicroProfile 1.2MicroProfile 1.1 MicroProfile 1.0 MP Config 1.0 MicroProfile 2.0 MicroProfile 2.1 MicroProfile 2.2 MicroProfile 1.3 MicroProfile 1.x
  7. 7. © 2017 IBM Corporation7 MicroProfile 1.0 (Fall 2016) jaxrs-2.0 cdi-1.2 jsonp-1.0 MicroProfile 1.1 (August 2017) microProfile-1.0 mpConfig-1.0 MicroProfile 1.2 (Sept 2017) microProfile-1.1 mpConfig-1.1 mpFaultTolerance-1.0 mpHealth-1.0 mpMetrics-1.0 mpJwt-1.0 MicroProfile 1.3 (???) MicroProfile 1.2 mpTracing-1.0 mpOpenApi-1.0 MicroProfile 2.0 (1Q 2018?) MicroProfile 1.3 jaxrs-2.1 // Java EE 8 cdi-2.0 // Java EE 8 jsonp-1.1 // Java EE 8 jsonb-1.0 // Java EE 8 2017 2018 Aug Sept
  8. 8. © 2017 IBM Corporation Eclipse MicroProfile 1.2 (Sep, 2017) 8 MicroProfile 1.2 = Updated = No change from last release JAX-RS 2.0JSON-P 1.0CDI 1.2 Config 1.1 Fault Tolerance 1.0 JWT Propagation 1.0 Health Check 1.0 Metrics 1.0 = New
  9. 9. © 2017 IBM Corporation http://microprofile.io/ MicroProfile adds new enterprise Java capabilities for microservices Config Fault Tolerance Health Check Health Metrics JWT externalize configuration to improve portability build robust behavior to cope with unexpected failures ensure services are running understand the interactions between services while running resolve problems in complex distributed systems New in Eclipse MicroProfile Release 1.2: https://projects.eclipse.org/projects/technology.microprofile/releases/1.2 Robust Microservices
  10. 10. © 2017 IBM Corporation MicroProfile Config 1.1  Why? – Configure Microservice without repacking the application  How? – Properties from the built-in configure sources with default config ordinals: • META-INFmicroprofile-config.properties (default ordinal = 100) • System properties (default ordinal = 400) • Environment variables (default ordinal = 300) – Provide custom configure sources with a priority – Provide custom converters with a priority – Access properties 10
  11. 11. © 2017 IBM Corporation Provide a config source  Step 1: Create a class that implements org.eclipse.microprofile.config.spi.ConfigSource  Step 2: Register the class using service loader pattern – Create a file under META-INFserviceorg.eclipse.microprofile.config.spi.ConfigSource – Inside the file: put the fully qualified config source implementation class name  Step 2: Alternatively, directly call SPI to add a config source to a builder and then build a config – ConfigProviderResolver.getBuilder() .withSources(ConfigSource… configSources).build() 11
  12. 12. © 2017 IBM Corporation Provide a Converter  The config properties are all specified in strings in config sources.  In order to get a ultimate value other than the built-in types, a converter is needed.  Step 1: Create a class that implements org.eclipse.microprofile.config.spi.Converter  Step 2: Register the class using service loader pattern. – Create a file under META-INFserviceorg.eclipse.microprofile.config.spi.Converter – Inside the file: put the fully qualified config converter implementation class name  Step 2: alternatively, directly call SPI to add a config source to a builder and then build a config – ConfigProviderResolver.getBuilder() .withConfigSources(…).withConverters(Converter… converter).build() 12 public interface Converter<T> { /** * Configure the string value to a specified type * @param value the string representation of a property value. * @return the converted value or null * * @throws IllegalArgumentException if the value cannot be converted to the specified type. */ T convert(String value); }
  13. 13. © 2017 IBM Corporation Look up properties – Access configuration via • Programmatically lookup Config config = ConfigProvider.getConfig(); config.getValue(“myProp”, String.class); • Via CDI Injection @Inject @ConfigProperty(name="my.string.property") String myPropV; 13
  14. 14. © 2017 IBM Corporation MicroProfile Config  Static Config  Dynamic Config @Inject @ConfigProperty(name="myStaticProp" ) private String staticProp; @Inject @ConfigProperty(name="myDynamicProp ") private Provider<String> dynamicProp; microprofile-config.properties myStaticProp=defaultSValue myDynamicProp=defaultDValue Java Options -DmyStaticProp=customSValue -DmyDynamicProp=customDValue overrides
  15. 15. © 2017 IBM Corporation  OSGi r7 has Config Admin Config Admin PID Configuration com.acme Name=Bob Age= 18 12.1 Name = Andy Age = 22 pid=com.acme
  16. 16. © 2017 IBM Corporation Why bother to support MicroProfile Config in OSGi? o Future aspiration goal • Application using CDI, JAX-RS can run unchanged in OSGi, MicroProfile 1.0 • Applications using MicroProfile programming model including Config can run unchanged in OSGi
  17. 17. © 2017 IBM Corporation  How to support MicroProfile Config in OSGi? o MP Config Implementation bundle registers the ConfigProvider service o MP Config Implementation bundle registers CDI extension to register Config bean, a producer to produce config properties with the qualifier ConfigProperty o Depend on CDI in OSGi specification app bundle MP Config Impl ConfigProvider CDI beans
  18. 18. © 2017 IBM Corporation  Create an ecosystem with MicroProfile Config and Config Admin o Config Admin offer maps containing properties o Config Admin can be treated as a config source in MicroProfile Config with the specified the config_ordinal (a normal key value, 500 if not exists).
  19. 19. © 2017 IBM Corporation  OSGi r7 supports Converters o Not quite the same as the MicroProfile Config Conveter o Use converter adapter to convert OSGi converters to be used as MicroProfile converters o Call into OSGi converter service to do the conversion
  20. 20. © 2017 IBM Corporation20  Resources – http://microprofile.io/ – https://openliberty.io/ – https://www.eclipse.org/community/eclipse_newsletter/2017/september/
  21. 21. © 2017 IBM Corporation Thank you Special Thanks to BJ Hargrave for your contributions towards the integration part!

×