Skip to main content

Posts

Showing posts from June, 2019

How to use Spring Boot with MySQL database

Greetings!

Spring Framework simplifies working with databases by auto configuring connections, handling transactions, using ORM tool like hibernate, abstract sql by Spring Data Repository. We are going to focus on how to connect MySQL database with Spring Boot application.

Sprint Boot has many defaults. For databases, H2 in-memory database is the default database. It auto-configures in-memory databases even without connection url. Those are good for simple testing. For production use we need to use a database like MySQL.

Spring Boot selects HickariCP Datasource due to it is performance. When spring-boot-starter-data-jpa dependency in classpath it automatically pick HickariCP.

complete source code this blog post is here.

How to configure a database Obviously, to use a database in our application we need;
Database driver to connect to databaseConnection urlDatabase username and password In Spring Boot application we need to provide atleast connection url, otherwise it will try to configu…

Microservices - Distributed tracing with Spring Cloud Sleuth and Zipkin

Greetings!

Microservices are very flexible. We can have multiple microservices for each domain and interact as necessary. But it comes with a price. It becomes very complex when the number of microservices grow.
Imagine a situation where you found a bug or slowness in the system. How do you find the root cause by examinig logs?

Collect all the logs from related microservices.Pick the starting microservice and find a clue there using some id (userid, businessid, etc).Pick the next microservice and check whether the previous information are there.Keep going until you find which microservice has the bug.
I have followed that practise in one of my previous projects. It is very difficult and takes a lot of time to track an issue.
This is why we need to use distributed tracing in microservices. One place where we can go and see the entire trace.

It helps us by;
Asign unique id (correlation id) to all request.Pass unique id across all the microservices automatically.Record time information.Log…

Cracking Java8 Stream Interview Question

Greetings!

I have faced many interviews (too many to be frank) in my career as a software developer. In most of those interviews I have been asked to write a pseudo code for a given problem and implement it in Java. With Java8, this implementation mostly should be in Java8.
When I look back all those questions it can be simplified as below. (difficulty may be vary though).

Iterate over a given collection (stream)Filter the given data (filter)Transform into another format (map, reduce)Collect data into a collection (collect)or End the stream (forEach, min, etc)
Is this familiar to you? This should be. This is what we do in our daily work. But, if you are blindly using it you will see it as a difficult question to answer.
You need to have good understanding about intermediate and terminal operations. And, you need to really practise and use in daily work. It is meaningless to pass an interview without knowing these.
java-8-streams-intermediate-operations
java-8-streams-terminal-operations

Angular - Let's create a starter project

Greetings!

Angular has many things to learn though we can skip those and directly create simple project. It will be harder to study all the features first. So here, i'm going to directly create a simple starter project.

This is the end result of this tutorial.



Install Angular CLInpm install -g @angular/cli ng version
Create a projectng new angular-store --routing --style=scss cd angular-store npm install
This will create a basic app structure.
Run the projectng serve --open # short form ng s -o
With zero code, we have a running template. That's some power.

Angular Material Let's add material UI design into our project. For more information visit https://material.angular.io/
Below command will add angular material into our project and update neccessary files.
ng add @angular/material
We want to use material design component in our project. To add material components in a single place let's create a separate module named material and update it with neccessary materaial …

Microservices - Api Gateway

Greetings!

I was too busy past couple of days and lost my way of continuing Microservices series. So I decided to add simple dummy services service-a and service-b. Other than that, there is no change except the github repo.

https://github.com/slmanju/simple-microservice

In Microservices architecture we are dealing with many apis which work along or work with other services. Imagine that we are going to create a mobiile client using these client it will be very difficult to manage all services by that client. Or, imagine we expose our apis so that anyone can create their own client.
This is a good place to introduce a another service which act as a gateway to all other services. Third party clients will know only about this api.
Not only this, we can solve some other problems using Api Gateway.

Single entry point to all the services.Common place to log request and responses.Authentication users in single place.Rate limits.Add common filters.Hide internal services.

To create our api gate…