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.

Using Magnolia in a Microservices Architecture


Published on

Want to learn how to manage and deploy Magnolia in a microservices architecture? Here we will present the main patterns identified in such an architecture and describe how to implement them with Magnolia. We demonstrate an experimental approach based on Docker to create and orchestrate several microservices connected to Magnolia.

Published in: Technology
  • Be the first to comment

Using Magnolia in a Microservices Architecture

  1. 1. Using Magnolia in a Microservices Architecture Presented by Nicolas Barbé Broadcast on 2015-09-10
  2. 2. Nicolas Barbé Software engineer and technology enthusiast working for Magnolia
  3. 3. MICROSERVICES “Loosely coupled service oriented architecture with bounded contexts” Adrian Cockcroft
  4. 4. Your organisation can scale WHY DOES IT MATTER?
  5. 5. NOT A FREE LUNCH Distributed systems are complex ๏ Testability ๏ Eventual consistency ๏ Operational complexity
  7. 7. REQUEST - RESPONSE request response BLOCKED one to one and synchronous client server This is a service
  8. 8. PUBLISH - SUBSCRIBE publish one to many and asynchronous subscribetopic producer consumers
  9. 9. FACADE C Facade B A A facade provides an uniformed API abstracting several underlying services Request
  10. 10. PROXY C proxy B A A proxy delegates a request to one of the underlying services Request
  11. 11. CRUD Create / Read / Update / Delete Straightforward mapping to DB operators but does not perform well with task based UI
  12. 12. CQRS Different models for queries and commands Commands Queries
  13. 13. ROLE OF MAGNOLIA ๏ Editorial Content - Magnolia ๏ Dynamic or User Generated Content ๏ Content & Business Logic - Microservices ๏ Frontend - Magnolia ๏ Backend - Magnolia
  14. 14. MAGNOLIA ASK A proof of concept of a Q&A website like stack-overflow
  15. 15. WHICH SERVICES? References must be checked - Question / Answer - Question / User - Answer / User - Rating / Answer - Rating / Question Users have only one vote Answers are single threaded USERS QUESTIONS ANSWERS RATINGS
  16. 16. ARCHITECTURE USERS-COMMANDS users RATINGS-COMMANDS ANSWERS-COMMANDS QUESTIONS-COMMANDS USERS-QUERIES votes questions answers QUESTIONS-QUERIES ANSWERS-QUERIES pub pub pub pub sub sub sub sub sub sub sub sub sub req/res req/res sub Magnolia req/res req/res req/res
  17. 17. ANATOMY OF A MICROSERVICE Commands Queries QUESTIONS ‣ AskQuestion ‣ CloseQuestion { title: Eget lacinia odio sem nec elit? description: Cum sociis natoque penatibus et magnis dis parturient ontes, nascetur ridiculus mus. initiator: nbarbe createdAt: 2015-08-14T14:45:43
 closed: false } ‣ ListQuestions ‣ ShowQuestion { title: Eget lacinia odio sem nec elit? description: Cum sociis natoque penatibus et magnis dis parturient ontes, nascetur ridiculus mus. initiator: Nicolas Barbé createdAt: 2015-08-14T14:45:43 closed: false votes: 12 answers: 3 answersBucketId: fh34t738 }
  19. 19. CONTAINERS Additional layer of abstraction and automation of an OS
  20. 20. CONTAINERS OR VM? Actually both ! Virtual machine for the hosts Containers for the microservices
  21. 21. CONTAINER = MICROSERVICE ๏ Clear Boundaries ๏ Reproducible Builds ๏ Network Plumbing ๏ From Dev to Prod to Dev ๏ Uniform Operations - Packaging - Distribution - Deployment / Upgrade - Backup / Restore - Monitoring - Logging - Snaphots
  22. 22. DOCKERIZE MAGNOLIA $ echo 'FROM nicolasbarbe/magnolia-base MAINTAINER Nicolas Barbé "" RUN wget -nv magnolia/Magnolia%20CE%205.4.2/magnolia-bundled- webapp-5.4.2.war/download?use_mirror=autoselect -O $CATALINA_BASE/webapps/ROOT.war' > Dockerfile $ docker build -t magnolia . $ docker run -p 3000:8080 magnolia
  23. 23. TIPS & TRICKS ๏ Follows the recommendations of the Filesystem Hierarchy Standard ๏ Configuration through environment variables - INSTANCE_TYPE - DB_TYPE - DB_SCHEMA - DB_USERNAME - DB_PASSWORD - DEVELOP_MODE - CLUSTER_ID ๏ Tomcat & JVM settings can be customised COPY $CATALINA_BASE/bin/ ๏ Map a volume from the host to the container to persist the JCR repository -v /var/lib/magnolia/repositories:/var/lib/ magnolia/repositories ๏ Map a volume from the host to the container for the resources -v $MAGNOLIA_WEB_RESOURCES:/var/opt/magnolia
  25. 25. FROM DEV … Build a clone of the production environment locally with Docker Compose db-author: image: postgres environment: - POSTGRES_USER=magnolia - POSTGRES_PASSWORD=mysecretpassword author: image: nicolasbarbe/ms-frontend:1.0-SNAPSHOT command: run ports: - "3000:8080" links: - db-author:db environment: - INSTANCE_TYPE=author - DB_TYPE=postgresql - DB_ADDRESS=db - DB_PORT=5432 - DB_SCHEMA=magnolia - DB_USERNAME=magnolia - DB_PASSWORD=mysecretpassword Create a new container for the database Create a network link between the database and magnolia Create another container for Magnolia Configure the instance as an author and to use the postgresql driver Thanks to the link, we don’t have to specify the database IP address
  26. 26. … TO PROD ๏ Use a full Docker stack - Reuse the same Docker Compose definition - If the architectures are slightly different use extends keyword - Use Docker Swarm to deploy on multiple hosts - Use Docker Machine to provision the hosts ๏ But, wait, Docker Compose/Swarm are still in Beta - Use Kubernetes if you want a cluster with dynamic provisioning and hosts allocation - Use Ansible if you want static hosts provisioning and allocation (see my blog post*) ๏ In all cases use the same Docker Images ! *
  27. 27. SERVICE DISCOVERY Build a Service Registry to let Magnolia discovers the services automatically The Service Registry - Defines microservices in a YAML file - Discovers the services through environment variables, Java system properties, from the JCR or by value - Injects services in the templates - Provides a generic connector to build dedicated content apps in YAML services: questions: connection: host: QUESTIONS_QUERIES_HOST port: QUESTIONS_QUERIES_PORT type: env apiVersion: v1 resource: name: question properties: - name: id type: Integer - name: title type: String - name: description
  28. 28. DISPLAYING CONTENT [#assign id=ctx.getParameter("id")] [#assign question=httpfn.service("question").GET(id)] <div class="row"> <h2>${question.title}</h2> <h4>${question.initiator}</h4> <p class="lead"> ${question.description} </p> <div class="pull-right">Asked ${question.createdAt?datetime?date}</div> </div>
  29. 29. MANAGING CONTENT Presenters uses Query side Actions connect to the Command side
  31. 31. QUESTIONS?