Posts

Showing posts from April, 2022

Java - Best Practice - FAQ

1] Here  myListConsistOfSQL is the List<String> which consist of SQL scripts for execution PreparedStatement ps=null; try{          conn=getMyDBConnection(); for(String sql: myListConsistOfSQL) {          ps = conn.prepareStatement(sql);          ps.addBatch();          ps.executeBatch();     } } Catch(Exception e) {     throw new e; } finally {     if(ps!=null) {          ps.close();      }    if(conn!=null) {         conn.close();     } } 2] Map object to print the key and values using for each loop myDataMap.forEach((key, value) -> log.info("Details:: " + key + ":" + value)); myDataList.forEach(msg -> log.info(msg)); 3] Logger message utility class to hold details in list import java.util.ArrayList; import java.util.List; public class MessagesUtil { ...

Maven Command

Maven Command 1. Create the batch file with extension as ".bat" 2. Copy below contents into the file for build/clean install maven command echo Hello %USERNAME% echo Starting building component for your application set PATH="C:\apache-maven-3.6.0\bin";%PATH% cd C:\PROJECT_APP_PATH\ mvn clean install -P local echo DONE! timeout /t 15 Explain: Path variable will contain your exact location with bin directory of apache maven. -P {} -> Here based on your profile configuration like local, sit, uat, prod etc. build will automatically start

UNIX - Basic Commands

Basic Directory Commands  mkdir  To create a new directory by an user in Unix    $mkdir dir_abc rmdir  To remove a directory from the file system  $rmdir  dir_abc pwd  To get the present working directory  pwd  is used to identify the present directory in which the user is working.  $ pwd <enter>  cd  To change from the present working directory  Changing from one directory to the other is done by the command cd   $cd /usr/ dir_abc /AP   mv  To rename the files  mv  is used to change the name of files and directories  $mv fileabc filexyz ls  The command ls  is used to list the files and directories which are available in that current working directory  $ls <enter> cp To copy the contents of one file into another file  $ cp file1 file2 Copies file1 to file2  rm  To delete a file  rm command is used for deleting unwanted files/directories...

Java & Spring, Spring Boot Learning Links

Use below website links to understand basics of Java & Spring: 1] Beginner  https://www.geeksforgeeks.org/java/ https://howtodoinjava.com/java/basics/java-tutorial/ 2] Java-8 - Learning with examples & concepts https://mkyong.com/tutorials/java-8-tutorials/ 3] Spring Basics https://howtodoinjava.com/java-spring-framework-tutorials/ 4] Spring Boot https://howtodoinjava.com/spring-boot-tutorials/ https://www.javainuse.com/spring/sprboot

Spring Boot / Cloud and Microservices

 Microservices with Spring Cloud Spring Cloud Config Server and Bus Load Balancing with Ribbon and Feign Implement Naming Server with Eureka Implement API Gateway with Zuul Distributed Tracing with Zipkin Fault Tolerance with Hystrix RESTful Webservice: REST is a style of software architecture for distributed hypermedia systems Basic:  HTTP Request methods (GET, POST, DELETE, PUT, PATCH) Exception Handling --> Validation HATEOAS HTTP Response Status Code --> 200, 400, 500 series HATEOAS : H ypermedia A s T he E ngine O f A pplication S tate Advanced: Versioning, Swagger, Filtering, Monitoring, Content Negotiations, Internationalizations Tools/Framework:  Spring, Spring Boot, JPA, Maven, Postman MICROSERVICES REST +  Small Well Chosen Deployable Units +  Cloud Enabled (Scale-In/Out Instances)

Apache POI - Read from Excel

Read from Excel with APACHE POI Library: Add below library reference in pom.xml: <dependency>     <groupId>org.apache.poi</groupId>     <artifactId>poi</artifactId>     <version>3.17</version> </dependency> <dependency>     <groupId>org.apache.poi</groupId>     <artifactId>poi-ooxml</artifactId>     <version>3.17</version> </dependency> //Read from excel by row and each cell as column by passing file input path (.xls or .xlsx) private void readFromExcel(String xslFilePath) throws Exception { Workbook wb= null; try{     wb = WorkbookFactory.create(new File( xslFilePath)); //Get data sheet at index 0 (First Tab)     Sheet sh = wb.getSheetAt(0);     Iterator<Row> rowItr = sh.iterator();          while( rowItr .hasNext()){             ...

Top Microservices Patterns

  What are the top microservices patterns? When we dive into Microservices Architecture we can understand it comes with good advantages with some challenges to solve these challenges we need to follow certain patterns. Even Driven pattern - Thumb rule of microservices is to have individual database for each microservices , so you can imagine if you have services which will update database, in this situation you need to implement event driven pattern to maintain consistency between the database tables. Observability Patterns- We need a centralized logging service that aggregates logs from each service instance. For example, if you are using PCF(Pivotal cloud Foundry) does have Loggeregator, which collects logs from each component (router, controller, etc...) of the PCF platform along with applications . These we can connect to the Logger maintain systems like Splunk . Cross-Cutting Concern Patterns - To Explain this Config server is the best example , this is used to externalize th...

Text to Speech C# Program

#r "Newtonsoft.Json" #r "Microsoft.WindowsAzure.Storage" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; using System; using System.Net.Http; using System.Text; using System.IO; using System.Threading.Tasks; using Microsoft.WindowsAzure.Storage.Blob; public static async Task<IActionResult> Run(HttpRequest req, CloudBlockBlob outputBlob, ILogger log)         {             string subscriptionKey = "332133";             string ttsEndpoint = "https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1";             string accessTokenEndpoint = "https://centralindia.api.cognitive.microsoft.com/sts/v1.0/issuetoken";             string azureSpeechResourceName = "SampleSpeechText";             string voice = "Microsoft Server Speech Text to Speech Voic...