Book Image

Microservices with Clojure

By : Anuj Kumar
Book Image

Microservices with Clojure

By: Anuj Kumar

Overview of this book

The 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.
Table of Contents (18 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Managing application states with mount


Once the configuration parameters are defined using Omniconf, they are accessible across the namespaces as immutable data. The configuration parameters are often used to create stateful objects, such as database connections. For example, in the Consumer service project, Omniconf made it possible to create a consumer database by directly looking up the :datomic :uri configuration parameter within the create-consumer-database function.

The helping-hands.consumer.persistence/create-consumer-database function has a side effect of database being created and also a new connection being initialized to connect to the created database. This connection has a state that must be shared across other namespaces of the Helping Hands Consumer service that need access to the database. In the current implementation, the connection was initialized at the first call to the helping-hands.consumer.core/consumerdb as shown here:

(ns helping-hands.consumer.core
  "Initializes...