Microservices with Clojure
eBook - ePub

Microservices with Clojure

Anuj Kumar, Michael Vitz

Buch teilen
  1. 336 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Microservices with Clojure

Anuj Kumar, Michael Vitz

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Microservices with Clojure als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Microservices with Clojure von Anuj Kumar, Michael Vitz im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in Java. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781788626316

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...

Inhaltsverzeichnis