Posts

Reactive Glimpse Part - II

Reactive Concurrency Concurrency in Reactive universe has a little different flavour than what we experience in Imperative world. A Reactive flow by default Single Threaded in nature. But we can achieve concurrency with the help of the operators like subscribeOn(), observeOn() etc. along with the Schedulers that Rx provides. subscribeOn(): Asynchrously subscribes Subscribers/Observers to an ObservableSource on a Specified scheduler. onserveOn(): Makes an ObservableSource to send all notifications/events on a specified scheduler asynchronously. A few points that I would really like to state at the very beginning are: 1) The operators in a flow are always executed serially contextwise. 2) The Flow for a particular data item do not interfere with the flow for another data item belonging to the same ObservableSource. Let's try to understand the concurrency from the context of the below test case. @Test public void testConcurrency(){ rx.Observabl...

Reactive Glimpse-Part 1

Image
A peek into Observables. Reactive Approach/Principles has unfurled new dimensions of programming to us. Reactive Manifesto being the key, paved the way to approach things with a different eye and with its multilingual dominion we have Rx's omnipresence. For me it all started with RxJava and RxGroovy and now with ProjectReactor providing Specification to build Reactive Systems, Spring too incorporating Reactive principles in its 5th edition and together with Java 9 flow, it is evident that Reactive is gaining both strength and momentum. Even different tools/api now extend their reactive support, be it JDBC, RabbitMQ, Kafka etc. My interaction with the Reactive Dimension has been limited to Observables, Observers/Subscribers accompanied by several other operators. Thats fairly little I can understand and the justification being I am JUST A BEGINNER HERE. From what I understood till now is Observables are the Data Sources and it is through Observers/Subscribers we ...

reacto - The Client Component

The rationale behind detailing the harmony among indivudual components both at the Server and the Client side, so that readers can get a clear picture of different REACTIVE components and their flows. RECATO is built on RxJava and Vert.x . The principles on which these two entities are based out promises Resilliency, Resposiveness, Elasticity, Event Driven Architecture and Asynchronous behaviour. All of these commits towards a more Scalable Architecture. Service Registry is the component through which we invoke commands. Implementations are: 1) VertxServiceRegistry. 2) LocalServiceRegistry. Let’s examine the control flow with VertxServiceRegistry. The Command Execution feature that VertxServiceRegistry provides is due to the implementation of ServiceRegistry interface which provides necessary methods to execute a given Command. With the given Command as input, alongside with ServiceDiscovery , all the records are fetched which are recently updated and having...

reacto - The Server Component

Reacto – A Function Reactive Microservices Library. Now, when we talk about any Microservice Library, the first thing that pops up in our mind is the service implementation to meet our business ends and along with that the client support to invoke those services. There exists a lot of features that makes this library pretty awesome and with that it must also be admitted that it is also quite easy to learn and start with. The Design Principles that has been followed while developing has been described well in its GITHUB home page. What we will really try,is to understand the orchestration among different components of this library, which in turn will aid in getting idea about Control Flow while we use this toolkit. There are two modules corresponding to Reacto: 1) reacto --> The Client 2) reacto-vertx --> The Server Counter Part. reacto-vertx uses Vert.x for Service Publishing and Service discovery along with other features corresponding to Vert.x The Hear...

REACTO - A Functional Reactive Microservices Framework

What’s new in Spring 5? This is the most anticipated ask for any Spring aspirant and to be honest why it shouldn’t be, because Spring is such a awesome framework that we always ask more from it. This time too Spring came with a bunch of interesting and cool features. Java 8 is now an inevitable part of Spring 5 and so here the magic begins. Out of all the features that Spring 5 provides that most interesting ONES seems to me are: 1) Spring is now FUNCTIONAL – Functions are now First Class Citizens and they can passed anywhere. This is where Lambdas comes in. 2) Spring is now REACTIVE – Spring now supports Reactive Extensions (Rx) and it supports the Reactive Manifesto, the concepts on which the Reactive Programming is based. This post is not about the features that Spring 5 embeds. In this post we are going to discuss about a Microservice framework known as REACTO. The main aspect that distinguishes this framework from others is that its Fully FUNCTIONAL and REACTIVE...

Elastic Search with Spring PART II

1) Index creation or deletion: For Nested Type (Index name is Book) and Parent - Child Relationship (Index name is ParChild) @RequestMapping(value="/addIndex",method = RequestMethod.POST) def addBookIndex(@RequestParam(name = "indexName")String indexName){ logger.info "****** Adding Book Index: $indexName in ELASTIC DB......" def result = elasticsearchTemplate.createIndex(indexName) logger.info "****** Result is: $result " result } @RequestMapping(value="/deleteIndex",method = RequestMethod.POST) def deleteBookIndex(@RequestParam(name = "indexName")String indexName){ logger.info "****** Deleting Book Index: $indexName in ELASTIC DB......" def result = elasticsearchTemplate.deleteIndex(indexName) logger.info "****** Result is: $result " result } 2) Creating Mapping Type Whenever we save a doc...

Elastic Search with Spring

Image
ElasticSearch quite a familiar term. The first question that comes in our mind is: 1) What ElasticSearch is? & 2) Why should we use it? So to answer the first question, I would like to describe ElasticSearch as a wrapper over Apache Lucene (Apache Lucene is a high performance, text search engine library written in Java). So, ElasticSearch in its core is a distributed full-text search engine which is incredibly easy to scale (because of its well designed anatomy), returns results at a lightning speed (because of its analyzers which tokenize the texts and creates a reverse indexing just like the indexing of a book, a variety of analyzers are available), schema free in nature and supports JSON. The best part about elastic search which I experienced is all its functionalities are being exposed as REST services. ElasticSearch is a distributed NO SQL database where every input to it goes in JSON format and it has its very own way of storing data in data file...

Spring Security Oauth2 with JWT

Learning OAuth2 security protocol has always been one of my prime objectives. After integrating JWT token with Spring Security, I thought of giving a try with learning OAuth2 with Spring Security, as Spring Security provides implementation for OAuth2. To know the basics of OAuth2 I followed this. This article along with Aaron Parecki's blog really helped me in getting the concept behind this security protocol. Let's revise the components involved here: •Resource Owner •Client •Resource Server •Authorization Server and the grant types are: •Authorization Code •Implicit •Resource Owner Password Credentials •Client Credentials We have implemented both the Resource and Authorization server at the same endpoint for the sake of simplicity, however we can implement them separately too. And out of the four grant types I have been successful in experimenting with the last two only. I will try to share those experience here. I have selected JWT as...

Security with JWT Token (Spring Security)

Spring Security has always been one of my favourites which I explore often, since the time of xml configuration. This time I tried to implement Security with JWT token using Spring Security module (Java config) and I must say the java config has changed much since the time of XML configuration. Let’s chalk out the high level flow first: 1) User at first will fetch the JWT token from the URL: http://localhost:8080/SpringToken/auth by passing the user id and password in json format in the request body. We will make this URL “permit all” in Spring Security so that Spring does not enforce any authentication or authorization rule for this URL and anonymous authentication is implemented with AnonymousAuthenticationToken. This URL invokes a Handler method which generates JWT token sets it in the Security Context holder and returns it to the client. 2) The client while making subsequent request to access resources need to set the token in the request header named X-Aut...

Centalized Log Analysis & Processing

Image
Logging is always being considered as a fundametal and inherent part of any application, irrespective of the language and platform chosen. By the question arises that "Why Logs are very important???" Beacause I think it is the logs that help us get the real time impression of our application behaviour, i.e the user stimulus, the system responding to it, all the data that are being acted upon etc. In a word the I can say not only the Lifecycle of the application but the human interactions too gets recorded while logging. So Logging is basically the process of recording application actions and state. The stream of events that gets captured while logging becomes a very important source of application's current state and the state to which it needs to be evolved. Today Logging becomes the source of data analytics and data mines are emerging out from it which is helps us to make the application behave in a more intelligent manner. But for all these to happen, we...

Spring Cloud - The Final FALLBACK

Image
Yes, the POST name The Final FALLBACK is absolutely inline with what we will discuss here. We are talking about HYSTRIX-THE CIRCUIT BREAKER , which provides the FALLBACK functionality in Microservices architecture. The Code can be accessed at GITHUB Hystrix - The Circuit Breaker: The fallback mechanism is one of the most prominent and important partner in a microservice landscape and it can be implemented with Hystrix in Spring Ecosystem. The vivid documentation can well be found at the official Site. Here is the basic implementation of Circuit Breaker with Hystrix. Our architectural landscape is almost similar to the following: The incoming request first arrives at the “GATEKEEPER”(ZUUL has also got RIBBON) , which routes it to the Feign Client, which is both “HYSTRIX” and “RIBBON” enabled. The “RIBBON” does the Load Balancing work smartly, and which we can see in action, if more than one instance of the service (here AUTH-SERVICE) is being deployed. Now, ...

Spring Cloud - Part 3

Image
This post will be dedicated to Centralized Configuration Management for Microservices architecture. The Codebase is present at GITHUB Spring-Cloud-Config: Spring Cloud Config provides us a Centralized way of managing configuration details or properties for different services. Other services can refer to this service for managing their configuration. The Starter Class looks like: @SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigStarter { public static void main(String[] args){ SpringApplication.run(ConfigStarter.class, args); } } We have defined configuration for our AUTH-SERVICE only. However we can define configuration properties for any number of services we like. Within src/main/resources we have defines config folder and define two properties file: 1) auth-service.yml 2) auth-service-dev.yml The first property file will be referred by AUTH-SERVICE when it was initialized in default profile, and the second ...

Spring Cloud - Part 2

Image
Clients are such an important part of any business architecture, because it is for them all the services are meant and we remain always committed in fulfilling their ends, and if they provide an easy interface to interact with them, then sure I cannot ask for more. To access the microservices, we either use: 1. Restemplate based client 2. Feign Based client. We will discuss both of them here. I have uploaded my code base at GITHUB When talking about clients that can access the services rather microservices registered in Eureka, the first approach we have taken is with “RESTTemplate” . The RESTTemplate that we have used (rather injected) in Spring-Cloud-Client is auto configured by Spring Cloud and uses Netflix Ribbon to do the micro-service lookup. Ribbon is the software based load balancer implemented at the client side helps to pick a microservice based on service-name (as registered with the Eureka) specified with the property: spring...

Spring Cloud

Image
Hi Friends!!!, It has been really long since last I wrote for Spring HATEOAS , and along with that I really want to apologize for not completing it and soon I am going to post all my finding on that. But before going into that I thought why not Refurbish ourseleves with something new, something really interesting. Here it is, Spring Cloud Spring is always considered as an onestop need for all the requirements, and when I say that I mean in each and every aspect, which makes Spring essentially an ecosystem. Spring Cloud is no exception to that. Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems. 1) configuration management 2) service discovery 3) circuit breakers 4) intelligent routing 5) micro-proxy 6) control bus 7) one-time tokens 8) global locks 9) leadership election 10) distributed sessions 11) Cluster state. With the MICROSERVICES gaining popularity at a fast pace, becau...