Posts
Spring Cloud Feign
Often a service needs to call Http endpoints , Feign comes from the OpenFeign project makes it easier to call http endpoints in a declarative fashion. Spring has openfeign integraton through its Spring Cloud OpenFeign integration.
How To include feign clients The actual project for feign is OpenFeign https://github.com/OpenFeign/feign . Spring comes with it’s own starter . Add below dependency to the project
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> For an example let’s create a service named feign-serviceA which will call feign-serviceB .
Posts
Spring Boot Metrics
Introduction Observability is one of the pillars of modern microservices architecture. Application metrics is one dimension of that observbility. When an application runs on production we may want to know various operational metrics like memory,cpu ,threadpool usage etc as well as buisness metrics for example how many request for a particular operations are made. Spring boot with the help of micrometer enables application developers to expose various metrices.
Setup metrics To add support for metrics , we need to add actuator dependency
Posts
Spring Jpa
Introduction We started with a simple hello world application and we covered up to how to set up our database schema flyway. We are now ready to write some code which will interact with database. Before we jump on to code let’s look at a bit of history. Java has a nice JDBC api which helps us query database. Making it a base many ORM tools come into existence, Hibernate, Mybatis, Toplink to name a few.
Posts
Spring Flyway
Introduction Most of the services that we generally encounter in our daily job will simply take some input from users and populate database , and read from database and show it on UI. Each database has a schema, now it is rarely happens that we know each nitty gritty of our domain and come up with a perfect schema at day one. Most of the time we go thorugh an iterative process of modifying our schema as and when requirments change.
Posts
Spring Rest Openapi
Till now we have seen how to generate a new spring boot application and then how to containerize it. However our application till does not have any functionality. Today we will see how to create a REST API with Spring boot. However we will take a schema first approach and we will generate the REST API stub using the schema. This article will show how a OpenAPI specification looks like and how can we generate our REST API stub using the schema.
Posts
Spring Dockerize
In my previous post we saw how to create a simple spring boot application which actually does nothing much. I also touched about how to package that as jar file and run locally. However currently in production environment docker is hugely adopted. In this post we will see how to dockerize our spring boot application.
First Step, just works FROMubuntu:18.04ARG MAVEN_VERSION=3.8.5ARG BASE_URL=https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries# Install JavaRUN apt-get update \ && apt-get install -y curl\ && apt-get install -y openjdk-17-jdk ca-certificates-java\ && apt-get clean \ && update-ca-certificates -fENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64RUN export JAVA_HOME# Install MavenRUN curl -OLs ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.