Saturday, 4 June 2022

Microservice Design Pattern


Microservice design principles –

1.       Domain driven design

2.       Single responsibility principle

3.       High cohesion & low coupling

4.       Decentralized data

5.       Failure isolation

6.       Fault tolerance

7.       Hexagonal architecture

8.       Continuous delivery with DevOps

9.       Continuous monitoring & distributed tracing


Microservice design pattern –

1.       Decomposition pattern

2.       Integration patter

3.       Database pattern

4.       Observability pattern

5.       Cross cutting concern pattern


Decomposition pattern: -

1.       Decomposed by business capability

2.       Decomposed by subdomain

3.       Strangler pattern

4.       Bulkhead pattern

5.       Sidecar patter


Integration patter

1.       API gateway pattern

2.       Aggregators pattern

3.       Proxy pattern

4.       Gateway routing pattern

5.       Chained routing pattern

6.       Chained microservices pattern

7.       Branch pattern

8.       Client-side UI composition pattern


Database pattern

1.       Database per service

2.       Shared database per service

3.       CQRS pattern

4.       Event sourcing pattern

5.       SAGA Pattern


Observability pattern

1.       Log aggregation pattern

2.       Performance metrics pattern

3.       Distributed tracing pattern

4.       Health check pattern


Cross cutting concern pattern

1.       External configuration pattern

2.       Service discovery pattern

3.       Circuit breaker pattern

4.       Blue green deployment pattern

5.       Canary deployment pattern

Saturday, 2 May 2020

Date Format conversion



Important code snippet for Date conversions and methods-

Here we are covering different conversion of date more frequently used-

Covert Date String to Date object

package com.featuretest.basics;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

class TestMain {
public static void main(String[] args) throws ParseException {
      String dateString = "31/05/1988";
      Date dateObj = new SimpleDateFormat("dd/MM/yyyy").parse(dateString);
      System.out.println(dateString + "\t" + dateObj);
}
}


Covert Date object to localDateTime

package com.featuretest.basics;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

class TestMain {
public static void main(String[] args) throws ParseException {
      Date date = new Date();
      LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
      System.out.println(localDateTime);
}
}

Date conversion from one format to another

package com.featuretest.basics;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

class TestMain {
public static void main(String[] args) {

String dateString = "2019-12-19 04:10:00";
String convertedDate = dateFormatConversion(dateString, "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd");
System.out.println(convertedDate);
           
// Using Java 8 DateTime API
String convertedDateJava8 = dateFormatConversionJava8(dateString, "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd");
System.out.println(convertedDateJava8);
}
     
private static String dateFormatConversion(String dateString, String inputDF, String outputDF) {
SimpleDateFormat sdf = new SimpleDateFormat(inputDF);
Date date = null;
try {
      date = sdf.parse(dateString);
} catch (ParseException e) {
      e.printStackTrace();
}
SimpleDateFormat newFormat = new SimpleDateFormat(outputDF);
String output = newFormat.format(date);
return output;
}
     
private static String dateFormatConversionJava8(String dateString, String inputDF, String outputDF) {
DateTimeFormatter oldDTF = DateTimeFormatter.ofPattern(inputDF);
DateTimeFormatter newDTF = DateTimeFormatter.ofPattern(outputDF);
LocalDateTime datetime = LocalDateTime.from(LocalDate.parse(dateString, oldDTF).atStartOfDay());
return datetime.format(newDTF);
}
}


Tuesday, 24 September 2019

Enable HTTPS URL for Spring Boot wep application


Enable SSL certificate in spring boot application.
To enable https URL first we need to create an SSL certificate and configure the SSL certificate with spring boot application.


Create SSL certificate –
Navigate to the java installation directory, inside bin folder there is keytool executable file.
Run below command to generate jks file.
keytool -genkeypair -alias cert -keyalg RSA -keysize 2048 -keystore cert.jks -validity 3650
Run below command to get the content of keystore-
keytool -list -v -keystore cert.jks


Create a spring boot application–
Copy the certificate jks file in src/main/resources folder
Add below property in you application.yml file
server.port: 8443
server.ssl.key-alias: cert
server.ssl.key-store-password: ********
server.ssl.key-store: classpath:cert.jks
server.ssl.key-store-provider: SUN
server.ssl.key-store-type: JKS
Now you can access the url with https 
Refer below repository for project-
Enable SSL URL for web application