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...