Tag Archives: Java

Apache Commons Collection – MultiValuedMap

Apache Commons Collection is a library of useful data structures, collections, and algorithms in Java. MultiValuedMap is one of the data structures present in the Apache Commons Collection. MultiValuedMap is a Map that allows multiple values for a single key. It is a useful implementation of a one-to-many relationship. You can add multiple values to the same key, and the key-value pairs are stored in the order in which they are added.

Here’s an example Java code of using MultiValuedMap:

import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
public class MultiValuedMapDemo {
    public static void main(String[] args) {
        MultiValuedMap<String, String> multiValuedMap = new ArrayListValuedHashMap<>();
        multiValuedMap.put("Key1", "Value1");
        multiValuedMap.put("Key1", "Value2");
        multiValuedMap.put("Key2", "Value3");
        System.out.println(multiValuedMap.get("Key1"));
    }
}

Continue reading Apache Commons Collection – MultiValuedMap

Spring Cloud: Getting started with Hystrix Dashboard

This is a quick tutorial on Hystrix dashboard. Hystrix dashboard allows you to view the overall status of your Spring cloud application at a single glance. It provides access to vital metrics of your application and gives you a graphical representation of those for better understanding.

This post is the continuation of Spring Cloud: Adding Hystrix Circuit Breaker and Spring Cloud: Playing with Hystrix Circuit Breaker. Please go through those post, if you haven’t. Those posts explain about Hystrix circuit breaker.

TL;DR You can download whole project by clicking following link.

Continue reading Spring Cloud: Getting started with Hystrix Dashboard

Spring Cloud: Exploring Spring Cloud Config Server (GIT Mode)

In the last tutorial, we have seen Spring Cloud: Exploring Spring Cloud Config Server (Native Method). In this tutorial, we will look into the GIT base method.

Spring cloud config allows you to have applications/micro-services configuration at a centralized place. Since we are working on spring micro-services. We may have hundreds of micro-services running together. Now we want to manage configuration for hundreds of those micro-services. It would be a big pain if we do it manually. Instead, we will use the config server provided by Spring Cloud to manage that configuration from a central place.

We are going to achieve the same goal here which we discussed in the earlier tutorial. But here we will move our configuration to a GIT repository.

TL;DR You can download whole project by clicking following link.

Continue reading Spring Cloud: Exploring Spring Cloud Config Server (GIT Mode)

Spring Cloud: Exploring Spring Cloud Config Server (Native Mode)

This is a quick tutorial on Spring Cloud Config Server. In brief, Spring cloud config allows you to have applications/micro-services configuration at a centralized place. Since we are working on spring micro-services, in production we may have hundreds of micro-services running together. Now if we want to manage configuration for hundreds of those micro-services then it would be a big pain if we do it manually. Instead, we will use Spring cloud config server to manage that configuration from a central place.

TL;DR You can download whole project by clicking following link.

Continue reading Spring Cloud: Exploring Spring Cloud Config Server (Native Mode)

Spring Cloud: Adding Filters in Zuul Gateway

This tutorial is the continuation of Spring Cloud: Exploring Zuul Gateway tutorial. In this tutorial, we will be exploring the functionality of filters provided by Zuul.

As discussed earlier Zuul provides various filters which we can use for request validation or processing. Let’s say if you have an incoming request and if you want to check whether the user is authenticated or not, you can use Zuul pre-filter for this.  If your request is processed and if you want to encrypt the response you can use Zuul post filter. The major upside of Zuul filter is, you can manage all of your filters at a centralized location.

Zuul has provision to create following four types of filter.

  1. pre filters run before the request is routed.
  2. route filters can handle the actual routing of the request.
  3. post filters run after the request has been routed.
  4. error filters run if an error occurs while handling the request.
Continue reading Spring Cloud: Adding Filters in Zuul Gateway

Spring Cloud: Exploring Zuul Gateway

This is a quick tutorial for Spring cloud Zuul component. In this tutorial, we will explore Zuul functionality and will create a gateway to our Spring cloud environment using Zuul.

What is Zuul?

Zuul is a gateway component in Spring cloud ecosystem. It provides access to the services present in our Spring cloud from services/applications which are outside of our environment.

Zuul creates a single entry point for our application which we can use from the outside world. In our environment, we might have 100’s of services running, each one serving a special purpose. Now if we want to access those services via another network or from the internet, then exposing those 100 services will not be a great idea.

In such cases, Zuul comes handy. It provides us with a single proxy to access those services. Apart from that Zuul also provides request filters. We can use those to check/process each and every request before it hits the actual service.

TL;DR You can download whole project by clicking following link.

Continue reading Spring Cloud: Exploring Zuul Gateway