Microservices on application container cloud service Maarten Smeets 07-06-2018
Integration consultant at AMIS since 2014 About Maarten Integration consultant at AMIS since 2014 Several certifications SOA, BPM, MCS, Java, SQL, PL/SQL, Mule, AWS, etc Enthusiastic blogger http://javaoraclesoa.blogspot.com https://nl.linkedin.com/in/smeetsm @MaartenSmeetsNL
Nominate yourself or someone you know: acenomination.oracle.com 500+ Technical Experts Helping Peers Globally 3 Membership Tiers Oracle ACE Director Oracle ACE Oracle ACE Associate Connect: bit.ly/OracleACEProgram oracle-ace_ww@oracle.com Facebook.com/oracleaces @oracleace Nominate yourself or someone you know: acenomination.oracle.com
Microservices on Application container cloud service architecture Twelve factor Application Application container Cloud service Spring boot Documenting your api Using the ACCS cache with the ACCS Java SDK Deploying and running On ACCS
Microservice architecture in the cloud
Microservice architecture in the cloud the challenges are different from on premises Environment differs Administration, connectivity Security The entire world can access your services DTAP environments Local development / testing? Scalability
Twelve factor application HOW Codebase Backing services One codebase tracked in revision control, many deploys Treat backing services as attached resources Dependencies Build, release, run Explicitly declare and isolate dependencies Strictly separate build and run stages Config Processes Store config in the environment Execute the app as one or more stateless processes
Twelve factor application HOW Port binding Dev/prod parity Export services via port binding Keep environments as similar as possible Concurrency Logs Scale out via the process model Treat logs as event streams Disposability Admin processes Maximize robustness with fast startup and graceful shutdown Run admin/management tasks as one-off processes
Application Container Microservice architecture in the cloud 12 factor application: A methodology for building SaaS apps Smooth transition from dev to prod Easy integration with underlying platform ACCS is more GUI based and Heroku is more commandline / configuration file based. Deployment to Heroku is much faster! Application Container Cloud Service
Application container cloud service On demand scale out/in. Adding/Removing instances On demand scale up/down. Adding/Removing memory per instance Automatic load balancer configuration One click patching Easy to configure service bindings
Application container cloud service Why is this my favorite cloud service? Clean contract, language independent
Implementing microservices many choices Example Java SE, Spring Boot
Spring boot but why? Popular Java is very popular! #1 TIOBE index #3 on Stackoverflow and Github Netflix uses it Rich in features Uses Spring but with many shortcuts. Spring provides a lot of out of the box functionality such as integration and security Performant Spring Boot outperforms JavaScript on Node if you do the same things Like validation, authentication, formatting Fast to develop Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". https://octoverse.github.com/ https://insights.stackoverflow.com/survey/2017 Performance: https://www.linkedin.com/pulse/nodejs-vs-java-which-faster-apis-owen-rubel Na application server required. Ideal to just run a Jar in a Docker container Netflix uses it Spring is a solid framework a large codebase many contributors Spring Boot makes using Spring easy by taking an opinionated view Minimal configuration required for 80% of the use cases Designed to get you up and running as quickly as possible. Does not require an application server (has embedded Tomcat) You just need a JVM to run
Spring boot implementing microservices Documentation Spring Boot on ACCS Spring Boot on Docker Using the Application Cache
Spring boot Documentation Contract first (design first) Generate Spring Boot code using Smartbear Swaggerhub You can even generate code from your Maven build using swagger-codegen https://rphgoossens.wordpress.com/2018/02/10/swagger-generation-automation-or-creating-the-bottling-line/ https://swaggerhub.com/blog/api-design/design-first-or-code-first-api-development/ Internal API’s -> code first External API’s -> design first. Better communication and better experience Useful for quick stub generation https://swaggerhub.com/blog/api-design/design-first-or-code-first-api-development/
Spring boot Documentation Code first Generate Swagger documentation from annotations code using springfox.io libraries
Spring boot documentation code First Add dependencies to pom.xml Create Swagger configuration class Annotate your API’s
Spring boot documentation Add the SpringFox dependency to the pom.xml
Spring boot documentation Which APIs to generate documentation for
Spring boot documentation Describes the API Describes the API operation
Spring boot documentation
Spring boot documentation Easy to import Swagger documentation in a tool like Postman
Use dockerfile-maven-plugin Spring boot on docker Why? To test locally Create a Dockerfile Use dockerfile-maven-plugin In your pom.xml
Spring boot on Docker Get base images from public registries OpenJDK on Alpine Linux https://spring.io/guides/gs/spring-boot-docker/ Oracle JDK on Oracle Linux First is easy. No need to create accounts, works out of the box Second requires an account on store.docker.com and requires you to accept a license ACCS is OEL7 Why? To test locally https://github.com/oracle/docker-images/tree/master/OracleJava + + http://javaoraclesoa.blogspot.com/2018/03/running-spring-boot-in-docker-container.html
Spring boot on Docker Dockerfile mvn package dockerfile:build Add Dockerfile. Specifies container base mvn package dockerfile:build docker run -p 8081:8081 maartensmeets/accs-cache-sample:latest https://github.com/spotify/dockerfile-maven
Spring boot on Docker: different from ACCS There is no local ACCS environment You cannot test deployment locally ACCS bindings cannot be tested locally LocalSessionProvider is available for the cache The local environment differs. No loadbalancer, no internal and external hostnames Cache can be unittested
build a zip to deploy to accs What should be in the ZIP How do you create those files
Spring boot on ACCS build a deployable ACCS Deployable ZIP manifest.json deployment.json uberJAR.jar Create with the maven-assembly-plugin Create with the spring-boot-maven-plugin
Spring boot on ACCS build a deployable Describes what should go in the ZIP file for ACCS JAR + manifest.json + deployment.json Creates a Spring Boot über JAR with dependencies which ‘just runs’
Spring boot on ACCS deploy! manually
Spring boot on ACCS deploy! Developer cloud service
Using the application cache Create an application cache How to access the cache using the Java SDK
Using the application cache but why? Share state Cache slow service responses between technologically diverse stateless services like session data
Using the application cache Java SE App 1 Java SE App 1 Java SE App 3 Node JS App 1 Multiple apps can use the same application cache. A single app can use a single application cache Application cache runs on Coherence Useful for sharing session state across apps or app nodes. Application Cache 1 Application Cache 2 Customers Shopping carts Inventory Customers Shopping carts Inventory
Using the application cache how fast is it? Environment ACCS: 1 OCPU, 1 Gb Cache: 2Gb Basic Tested with GET request, small payload Average response time for 3500 requests, 20 threads, 60s End to end: 236ms (no significant difference REST / GRPC) GRPC: 5ms (1ms - 40ms) REST: 3ms (0ms - 70ms) Local: 0ms
Using the application cache
Using the application cache The cache name should not contain characters like ‘-’ This will cause the creation to fail (specifically LBaaS configuration)
Using the application cache Or in the deployment.json file or by manually adding a binding This does two things Ensuring there is secure network connectivity to the cache Make connection information to the cache available as parameters inside the Docker env
Using the application cache dependency challenges Java 9 lacks some libraries from previous SDK’s Additional dependencies needed Additional GRPC libraries are required
Using the application cache in spring boot Controller Exposes resources / presentation E.g. RestController Implement logic to use the cache or another repository Service Service / operation Implement cache code Repository Handles connectivity / persistence / DAO Entity The resource
Using the application cache in spring boot Oracle provides an open source SDK Java Client Caching SDK for Oracle Application Container Cloud Service https://github.com/oracle/accs-caching-java-sdk Also allows local development
Using the application cache in spring boot Service DbRepository CacheRepository Get requests directly to the cache Put requests to both Cache Loader Serializer
Using the application cache in spring boot Can be a Local or Remote. Remote requires an URL Create a SessionProvider Use the SessionProvider to create a Session Use the Session to get a Cache object Use the Cache object to access the cache The session can be REST or gRPC (HTTP/2) based Oracle provides a client SDK: https://blogs.oracle.com/developers/introducing-application-cache-client-java-sdk-for-oracle-cloud which has been open sourced: https://github.com/oracle/accs-caching-java-sdk Allows you to configure Expiry Determines validity of cached objects Loader This is called when there is no cache hit Serializer Objects need to be serialized to be put in the cache
Application container cloud service good to know Deployment Sometimes old deployment ZIP files are used Recommendation: script removing files from storage cloud Debugging Can be time-consuming. A single deployment can take minutes. The Java Client SDK does not provide support for a findAll method
Application cache good to know Expiry Has issues with the LocalSessionProvider Tip: set it to never expire Environment differences Working locally is no guarantee for working in the cloud! Dependencies / performance Test with both GRPC and REST. REST could be faster! You can’t remove a cache which has bindings to applications Availability During patches, updating bindings -> implement retries or error handling
Want to learn more? Java Python Complete working sample Spring Boot on ACCS with Application Cache https://github.com/MaartenSmeets/springboot A sample of using the cache. Application is Jersey based (no Spring) https://github.com/abhirockzz/app-container-cloud-cache-example Python A minimal sample of using Python on ACCS https://github.com/MaartenSmeets/pythonscripts/tree/master/microservice-accs/minimal-sample An elaborate sample of using Python on ACCS https://dzone.com/articles/deploy-a-python-application-to-oracle-application Also see https://community.oracle.com/community/oracle-cloud/oracle-cloud-developer-solutions/blog/2017/06/06/build-oracle-app-container-cloud-cache-based-application-cicd-using-oracle-developer-cloud