Posts

Method Reference in Java Streams

In Java Streams, a method reference is a shorthand notation for a lambda expression representing a specific method. It provides a more concise way to express certain types of lambda expressions. Method references are especially useful when you want to use an existing method as a lambda expression, avoiding unnecessary boilerplate code. There are four types of method references: 1) Reference to Static Method // Lambda expression nameList . stream (). forEach ( s -> System . out . println ( s )); // Method reference nameList . stream (). forEach ( System . out :: println ); 2) Reference to an Instance Method of a particular object: // Lambda expression nameList . stream (). forEach ( s -> members . validate ( s )); // Method reference nameList . stream (). forEach ( members :: validate ); 3) Reference to an Instance Method of an Arbitrary Object of a Particular Type: List < String > countryName = Arrays . asList ( "India" , "America" , "Russia...

AWS Lambda - Introduction (Bring your own code)

Image
AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS) that allows developers to run code in response to events without needing to manage servers. It is a Serverless Compute Service, where you bring your own code and run them without provisioning servers. With AWS Lambda, you can run programs for virtually any type of application or backend services without having to worry about provisioning, maintaining or waiting for service to be built. Some of the advantages are.  It automatically scales depending on the amount of user traffic you have, all way up to thousands of executions running at the same time, or all way down to zero and you only have to pay for what you use.  Easily monitor code performance in real time through CloudWatch .  Supports programs written in the most popular language used today.  It also has AP extensions that allows you to use other programming languages not listed. COBOL is one such extension. How does it work? ...

What is the difference between Controller and RestController?

When working on controllers in Spring, you would have seen there are two annotations which can be used to configure the controllers @Controller and @RestController. @Controller is the traditional annotation used widely in Spring MVC, in which the controller is used to create the Model Object which contains data and the return the View object. @RestController is a Restful webservice controller, which simply return an object and transmits the object data in HTTP Response in JSON or XML format. So, the main difference is the way the HTTP response body is created. When you annotate @RestController for the controller, all the methods are written as objects instead of views.  Moreover @RestController is same as @Controller + @ResponseBody. Even though if you use @Controller, you can still return data. If you use @ResponseBody annotation. @Target ({ ElementType . TYPE }) @Retention ( RetentionPolicy . RUNTIME ) @Documented @Component public @ interface Controller { @AliasFor ( ...

How to remove files completely from git repository history

 If you want to remove a file from GIT, it is straight forward, the simple command git rm will remove tracked files from the git index, but it leaves a foot print in the history, you can traverse back and get the file back. Suppose if you wrongly committed a file, with some valid keys, deleting the file alone is not going to help. If it is a public repository, then the issue will be more, since there are many bots running on the web, which scan entire repository to look for sensitive keys like (AWS/GCP/Azure keys, Valid IP address etc..). So to get rid off the old foot print completely, we need to do the following steps. git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch FILE_PATH" HEAD git push -all The first command is a time consuming one, it's based on the number of commits for the files, since it has to go check each and every commit to erase the foot print. That's all, you won't see the file history again. Happy Programming...!!!

Spring Cloud Stream - Publish Message to RabbitMQ

Image
 Spring cloud stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems. It uses the Spring Integration project to provide connectivity to a message broker. It unifies lots of popular messaging platforms behind one easy to use API including RabbitMQ, Apache Kafka, Google PubSub etc..Without this framework, we will be writing lot of boilerplate codes to support different messaging platform, and it will go beyond maintainable.  Spring Cloud Stream relies on the concept of binder to handle the integration with a messaging or event streaming framework. The binders support the core feature of modern messaging/eventing systems, such as  Publish/Subscribe, Consumer Groups, Partitioning, Message-driven consumers, Polling based consumers.  Let's see some of the concepts, before we jump into the code Binder:  A binder handles the integration with single framework. This abstraction allows your code to be middlewar...

What is Terraform?

Image
 Terraform is a free and open source Infrastructure as code software tool created by HashiCorp. A declarative coding tool, Terraform enables developers to use a high-level configuration language called HCL(HashiCorp Configuration Language) to describe the "end-state" cloud or on-premises infrastructure for running application. One of the biggest advantage of Terraform is it's ability to deploy infrastructure across multiple platforms including private and public cloud, such as on-premise vSphere cluster or cloud solutions such as AWS, GCP or Azure, these are just a few of the many resources that Terraform can manage. Terraform supports lots of providers, hence can work with almost every infrastructure platform. You can download the respective binary from the following download link. All infrastructure resources can be defined within configuration files that has a .tf file extension. The configuration syntax is easy to read, write and pick up for a beginner. Below is the ...

Spring Boot - Eureka Server

Image
 Microservices communicate with each other through exposed endpoints. For this communication to take place the dependent service should know the address of the other microservice to invoke its endpoint through a REST call, to get its job done.  Traditionally, all these endpoints has been hardcoded in configuration properties of the respective system.  However, with dynamic scaling of services in place it become hard to keep track of their address every time a new instance was created or destroyed. To overcome this problem, we use Eureka servers. It contains a registry of services and a REST API that can be used to register a service, deregister a service, and discover the location of other services like running port and IP address. All of this happens dynamically as soon as the instance of the service comes up or is destroyed. Eureka comes with two components - Eureka Client and Eureka Server . Eureka Server Keeps a record of all the services which have registered. Enabl...

How to ignore empty lists in Jackson?

 Assume you are building a service which pushes the data to the client in JSON format. The data includes some list of objects, sometimes it will available, sometimes it may not. Below is the sample object, which we are using to build the JSON data. I have 4 list properties in this, suppose if one of the list properties is empty, in the JSON format, it will have an empty array. If the client accepts the empty array well and good, if not, we need to exclude it from the payload we are sending. public class ClientData { @JsonIgnore private Long orderId ; @JsonProperty ( "additional_info" ) private AdditionalInfoDTO additionalInfoDTO ; @JsonProperty ( "deed_current" ) private DeedCurrentDTO deedCurrent ; @JsonProperty ( "deeds_prior" ) private List<DeedPriorDTO> deedsPrior ; @JsonProperty ( "judgments_and_liens" ) private List<JudgementAndLienDTO> judgementAndLienDTOS ; @JsonProperty ( "mortgages" ) privat...

How to reset MYSQL root password in Windows if root password is forgotten?

Somehow I have forgotten my MYSQL root password. I tried all possible combination, but everything went in vain, so what the options I have? Either uninstall MYSQL and reinstall it again, since it is just my local development instance or need to figure out a solution to find out the password or change it. Uninstalling and reinstalling it, is not a wise solution. So other only option is change it. Below are the steps to change the root password for MYSQL in Windows. 1) Log on to your system as Administrator or make sure that you have the administrator privileges. 2) Stop the MYSQL server. To do that, open the Start Menu and type services. It will open the Services window, if not got to the Control Panel > System and Security > Administrative Tools and click Services there. Find the MYSQL services and stop it. 3) Create a text file containing Sql statement to update the root password, save the file in a specific location. Let assume the file is stored in the C drive, and file nam...

PHP LARAVEL Directory Structure

When you create a fresh laravel project, you will be provided with the following files and directory to start with. Let's walks through the directories one by one.   Directory Description app The app directory contains the core code of your application. Models, controllers, routes all goes in here.     bootstrap The bootstrap directory contains all the bootstrapping scripts (app.php) used for your application. This directory also houses a cache directory which contains framework generated files for performance optimization such as route and service cache files. config The config directory holds all your project configuration files (.config). database The database directory holds your database migrations, models and seeds. public The public directory helps in starting your Laravel project and also holds other scripts (JavaScript and CSS) a...

PHP LARAVEL - Simple CURD example - TUTORIAL - 1

In the post, you will learn how to create a simple LARAVEL CRUD application from scratch. Let's start with how we create a fresh project, configure DB settings and writing the necessary model and controllers to interact with DB. In order to create a fresh installation of Laravel project, open the command prompt and type the below command. This will create a fresh project named curdexample. composer create-project laravel/laravel curdexample Go, to the project and open .env file, and set the DB_CONNECTION to MySQL, since we will be using the MySQL as our database for this example. Update all other details like HOST, DATABASE, USERNAME and PASSWORD. DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= Let's create our first model object. Laravel uses the MVC architecture to organize the application into three separate parts (Model, View and Controller). Model defines the data access layer, so let's creating the model first. Open...