Microservices with Clojure
eBook - ePub

Microservices with Clojure

Anuj Kumar, Michael Vitz

Partager le livre
  1. 336 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Microservices with Clojure

Anuj Kumar, Michael Vitz

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

The common patterns and practices of the microservice architecture and their application using the Clojure programming language.About This Book‱ Relevance of the microservice architecture and benefits of Clojure's functional and simple features to implement it.‱ Learn best practices and common principles to avoid common pitfalls while developing microservices.‱ Learn how to use Pedestal to build your next microservices, secure them using JWT, and monitor them using the ELK stackWho This Book Is ForYou should have a working knowledge of programming in Clojure. However, no knowledge of RESTful architecture, microservices, or web services is expected. If you are looking to apply techniques to your own projects, taking your first steps into microservice architecture, this book is for you.What You Will Learn‱ Explore the pros and cons of monolithic and microservice architectures‱ Use Clojure to effectively build a reallife application using Microservices‱ Gain practical knowledge of the Clojure Pedestal framework and how to use it to build Microservices‱ Explore various persistence patterns and learn how to use Apache Kafka to build event-driven microservice architectures‱ Secure your Microservices using JWT‱ Monitor Microservices at scale using the ELK stack‱ Deploy Microservices at scale using container orchestration platforms such as KubernetesIn DetailThe microservice architecture is sweeping the world as the de facto pattern with which to design and build scalable, easy-tomaintain web applications. This book will teach you common patterns and practices, and will show you how to apply these using the Clojure programming language.This book will teach you the fundamental concepts of architectural design and RESTful communication, and show you patterns that provide manageable code that is supportable in development and at scale in production. We will provide you with examples of how to put these concepts and patterns into practice with Clojure. This book will explain and illustrate, with practical examples, how teams of all sizes can start solving problems with microservices.You will learn the importance of writing code that is asynchronous and non-blocking and how Pedestal helps us do this. Later, the book explains how to build Reactive microservices in Clojure that adhere to the principles underlying the Reactive Manifesto. We finish off by showing you various ways to monitor, test, and secure your microservices. By the end, you will be fully capable of setting up, modifying, and deploying a microservice with Clojure and Pedestal.Style and approachThis book highlights the merits of the microservice architecture and its implementation with Clojure. Learn to implement microservices by migrating a monolithic application to a microservice-based architecture.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Microservices with Clojure est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Microservices with Clojure par Anuj Kumar, Michael Vitz en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming in Java. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781788626316
Édition
1

Building Microservices for Helping Hands

"It's not the ideas; it's design, implementation and hard work that make the difference."
- Michael Abrash
Identifying bounded context is the first step towards building a successful microservices-based architecture. Designing for scale and implementing them with the right technology stack is the next and the most crucial step in building a microservices-based application. This chapter brings together all the design decisions taken in the first part of the book (Chapter 2, Microservices Architecture and Chapter 3, Microservices for Helping Hands Application) and describes the steps to implement them using the Pedestal framework (Chapter 6, Introduction to Pedestal). In this chapter, you will learn how to:
  • Implement Hexagonal design for microservices
  • Create scalable microservices for Helping Hands using Pedestal
  • Implement workflows for microservices using the Pedestal interceptor chain
  • Implement the lookup service of Helping Hands to search for services and generate reports

Implementing Hexagonal Architecture

Hexagonal Architecture (http://alistair.cockburn.us/Hexagonal+architecture), as shown in the following diagram, aims to decouple the business logic from the persistence and the service layer. Clojure provides the concept of a protocol (https://clojure.org/reference/protocols) that can be used to define the interfaces, that act as ports of Hexagonal Architecture. These ports can then be implemented by the adapters, resulting in a decoupled implementation that can be swapped based on the requirement. Execution of these adapters can then be triggered via Pedestal interceptors based on the business logic.

Designing the interceptor chain and context

The interceptor chain must be defined for each microservice of the Helping Hands application separately. Each interceptor chain may consist of interceptors that authenticate the request, validate the data models, and apply the business logic. Interceptors can also be added to interact with the Persistence layer and to generate events as well. The list of probable interceptors that may be a part of Helping Hands services include:
  • Auth: Used to authenticate and authorize requests received by the API endpoints exposed by the microservice.
  • Validation (data model): Used to validate the request parameters and map the external data model with the internal data model as expected by the business logic and underlying persistent store.
  • Business logic: One or more interceptors to implement the business logic. These interceptors process the request parameters received by the API endpoints.
  • Persistence: Persist the changes using one or more adapters that implement the Port Protocol defined for the microservice data model to be persisted.
  • Events: Generate events asynchronously both for other microservices as well as for monitoring and reporting. These interceptors are added at the end of the chain to generate changelog events of the persistent store for other microservices to consume.
Pedestal context is a Clojure map that contains all the details related to the interceptor chain, request parameters, headers, and more. The same context map can also be used to share data with other interceptors in the chain. Instead of adding a key to the context map directly, it is recommended to keep a parent key, such as tx-data, that contains a map of keys that are related to the data being processed by the microservice. It may also contain the validated user details for other microservices to consume.

Creating a Pedestal project

To start with the implementation, create a project by the name of helping-hands and initialize it with a Pedestal template as discussed earlier in Chapter 6, Introduction to Pedestal. Once the project template is initialized, update the project.clj file and other configuration parameters as per the development environment setup of the playground application of Chapter 4, Development Environment. Once configured, the project.clj file should contain all the required dependencies and plugins, as shown here:
(defproject helping-hands "0.0.1-SNAPSHOT"
:description "Helping Hands Application"
:url "https://www.packtpub.com/application-development/microservices-clojure"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[io.pedestal/pedestal.service "0.5.3"]

;; Remove this line and uncomment one of the next lines to
;; use Immutant or Tomcat instead of Jetty:
[io.pedestal/pedestal.jetty "0.5.3"]
;; [io.pedestal/pedestal.immutant "0.5.3"]
;; [io.pedestal/pedestal.tomcat "0.5.3"]

[ch.qos.logback/logback-classic "1.1.8" :exclusions [org.slf4j/slf4j-api]]
[org.slf4j/jul-to-slf4j "1.7.22"]
[org.slf4j/jcl-over-slf4j "1.7.22"]
[org.slf4j/log4j-over-slf4j "1.7.22"]]
:min-lein-version "2.0.0"
:source-paths ["src/clj"]
:java-source-paths ["src/jvm"]
:test-paths ["test/clj" "test/jvm"]
:resource-paths ["config", "resources"]
:plugins [[:lein-codox "0.10.3"]
;; Code Coverage
[:lein-cloverage "1.0.9"]
;; Unit test docs
[test2junit "1.2.2"]]
:codox {:namespaces :all}
:test2junit-output-dir "target/test-reports"
;; If you use HTTP/2 or ALPN, use the java-agent to pull in the correct alpn-boot dependency
;:java-agents [[org.mortbay.jetty.alpn/jetty-alpn-agent "2.0.5"]]
:profiles {:provided {:depend...

Table des matiĂšres