Spring Boot Admin – Admin UI for administration of spring boot applications

               As part of micro services development many of us are using Spring Boot along with Spring Cloud features. In micro services world we will have many Spring Boot applications which will be running on same/different hosts. If we add Spring Actuator to the Spring Boot applications, we will get a lot of out of the box end points to monitor and interact with Spring Boot applications. The list is given below.

ID Description Sensitive Default
actuator Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath. true
auditevents Exposes audit events information for the current application. true
autoconfig Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied. true
beans Displays a complete list of all the Spring beans in your application. true
configprops Displays a collated list of all @ConfigurationProperties. true
dump Performs a thread dump. true
env Exposes properties from Spring’s ConfigurableEnvironment. true
flyway Shows any Flyway database migrations that have been applied. true
health Shows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated). false
info Displays arbitrary application info. false
loggers Shows and modifies the configuration of loggers in the application. true
liquibase Shows any Liquibase database migrations that have been applied. true
metrics Shows ‘metrics’ information for the current application. true
mappings Displays a collated list of all @RequestMapping paths. true
shutdown Allows the application to be gracefully shutdown (not enabled by default). true
trace Displays trace information (by default the last 100 HTTP requests). true

The above end points provides a lot of insights about Spring Boot application. But If you have many applications running then monitoring each application by hitting the end points and inspecting the JSON response is tedious process. To avoid this hassle Code Centric team came up with Spring Boot Admin module which will provide us Admin UI Dash board to administer  Spring Boot applications. This module crunches the data from Actuator end points and provides insights about all the registered applications in single dash-board. Now we will demonstrate the Spring Boot Admin features in the following sections.

As a first step, create a Spring Boot application which we will  make  as Spring Boot Admin server module by adding the below maven dependencies.

Add Spring Boot Admin Server configuration via adding @EnableAdminServer to your configuration.

Let us create more Spring Boot applications to monitor via Spring Boot Admin server created in above steps. All the Spring Boot applications which will create now will be acted as Spring Boot Admin clients. To make application as Admin client, add the below dependency along with actuator dependency. In this demo I have created three applications like Eureka Server, Customer Service and Order Service.

Add below property to application.properties file. This property tells that where the Spring Boot Admin server is running. Hence the clients will register with server.

Now If we start the Admin Server and other Spring Boot applications we can able to see all the admin clients information in the Admin server dashboard. As we started our admin server on 1111 port in this example we can see dash-board at http ://<host_name>:1111. Below is the screenshot of the Admin Server UI.

Detailed view of an application is given below. In this view we can see the tail of the log file, metrics, environment variables, log configuration where we can dynamically switch the log levels at the component level, root level or package level and other information.

Now we will see another feature called notifications from Spring Boot Admin. This will notify the administrators when the application status is  DOWN or application status is coming UP. Spring Boot admin supports the below channels to notify the user.

  • Email Notifications
  • Pagerduty Notifications
  • Hipchat Notifications
  • Slack Notifications
  • Let’s Chat Notifications

In this article we will configure Slack notifications. Add the below properties to the Spring Boot Admin Server’s application.properties file.

With Spring Boot Admin we are managing all the applications. So we need to secure Spring Boot Admin UI with login feature. Let us enable login feature to Spring Boot Admin server. Here I am going with basic authentication. Add below maven dependencies to the Admin Server module.

Add the below properties to the application.properties file.

As we added security to the Admin Server, Admin clients should be able to connect to server by authenticating. Hence add the below properties to the Admin client’s application.properties files.

There are additional UI features like Hystrix, Turbine UI which we can enable to the dash-board. You can find more details here. The sample code created for this demonstration is available on Github.

Tagged with:
Posted in Spring, Spring Boot

Http/2 multiplexing and server push

Smart Techie

                 In this article we will see the main features for Http/2 specification. Till Http/1 the request and response processing between the client and server is simplex. That is, the client sends the request and server processes that , sends response back to the client. Then, client sends another request to server. If any of the request is blocked, then all other requests will have the performance impact. This biggest issue is tackled by introducing the request pipeline in Http/1.1. As part of request pipeline, the request will be sent in an order to the server. Server processes the multiple requests and sends the response back to the client in the same order. Again here the client and server communication is simplex. The below diagram depicts the client server communication happening with Http/1.0 and Http/1.1.

http/1 request processing

                 Till Http/1.1 the request and response are composed in text format and uses multiple TCP connections per origin. The issues like opening multiple TCP connections per origin, Text format, simplex communication is handled in Http/ 2. Now we will see how Http 2 processes request and responses.

http2 request processing

                    The Http/2 uses binary protocol to exchange the data. Http/2 opens single connection per origin and the same TCP connection is used to process multiple requests. Each request will be associated to a stream and the request will be divided into multiple frames. Each frame will have the stream identifier to which it belongs to. The client will send multiple frames belongs to multiple streams to the server asynchronously and the server will process the frames belongs to multiple streams and sends the response asynchronously to the client. The client will arrange the response based on the stream identifier. Here the communication is happening between the client and server simultaneously with out blocking.

              Another Http/2 feature is server push. When client requests for a resource from server, it pushes the additional resources along with the requested resources to the client to cache the data at the client side. This enhances the performance as the client cache is warmed up by the content.

http/2 server push

To know further about Http/2 go through the below links.

https://http2.github.io/

https://tools.ietf.org/html/rfc7540

http://royal.pingdom.com/2015/06/11/http2-new-protocol/

Tagged with: , ,
Posted in General

Java 9 : Convenience Factory Methods to create immutable Collections

Java 9

                             In this article we will see another JDK 9 feature to create immutable collections. Till Java 8, If we want to create immutable collections we use to call unmodifiableXXX() methods on java.util.Collections class. For example,  To create unmodifiable list, we should write below code.

The above code is too verbose to create a simple unmodifiable List. As Java is adopting functional programming style Java 9 came up with convenience, more compacted factory methods to create unmodifiable collections with JEP 269. Let us see how  that works.

Create Empty List:

Create Non-Empty List:

Create Non-Empty Map:

If you look at the above Java 9 factory method, the code is simple one liner to create immutable collections. In the coming article we will see another Java 9 feature. Till then, Stay Tuned!!!

Tagged with: ,
Posted in Java

jshell: The Java Shell (Read-Eval-Print Loop)

Java 9

                         In this article we will discuss about jshell(Java Shell) Java 9 feature. We can explore jShell with JDK 9 Early Access Release.  As of now the general availability of JDK9 is scheduled to 27th July, 2017. The jShell feature is proposed as part of JEP 222. The motivation behind jshell is to provide interactive command line tools to explore the features of java quickly. It is very useful tool to get the glimpse of Java features very quickly for the new learners. Already Java is incorporating functional programming features from Scala. In the same direction they want REPL(Read-Eval-Print Loop) interactive shell for Java as Scala, Ruby, JavaScript, Haskell, Clojure, and Python.

                       The jshell tool will be a command-line tool with features like, a history of statements with editing, tab completion, automatic addition of needed terminal semicolons, and configurable predefined imports.

After downloading the JDK 9, set the PATH variable to access jshell. Now, we will see how to use jshell. Below is the simple program using jshell. We no need to write a class with public static void main(String[] args) method to run simple hello world application.

Now we will write method which will add two variables and invoke method via jshell.

Now, we will create a static method with StringBuilder class without importing it, as jshell does that for you.

I hope you enjoyed jshell feature. In the next article we  will see another JDK 9 feature. Till then, Stay Tuned!!!

Tagged with: , ,
Posted in Java

Software Architecture – Hexagonal Architecture Pattern

software_architecture_patterns

                     In this article we will see “Hexagonal Architectural Pattern” also known as “Ports and Adapters” pattern. As developers so far we have created applications with tiered architecture styles like MVC (Model View Controller). With this architectural styles, up to certain extent we were able to decouple the domain logic with other functionalities. At times the domain logic use to leak into UI or other functionalities. As the core logic is getting leaked into other layers , the impact of the code change will have ripple effect on other modules. To avoid this we can go with “Ports and Adapters” architecture style.

                      The “Ports and Adapters” style will have domain logic as Core and the Adapters will have the application logic specific  to translate an interface from outside request  into a compatible one. The core and the adapters sits as inner layer. The ports sits on outer layer to interact with the external services. The below diagram depicts the above said architectural style.

hexagonal-architecture

                        The advantages of this style is the core logic abstracted from the out side world. The code is decoupled via the adapters. We can add or remove the new functionalities easily. We can perform testing of core logic and the adapters in isolation mode.

                      In the coming article we will see what is micro services architectural style? and what are the driving factors behind it? Till then Stay Tune!!!

Tagged with: ,
Posted in Design Patterns

Gatling – Integration with Maven

gatling-logo

                                               In this article we will see how to use Gatling with Maven. This approach enables us to integrate Gatling as part of continuous integration. Along with that we will see how to externalize properties used in simulation script and the dynamic data feeding using Gatling feeders. Let us see the above said features in action.

As a first step create a maven project and add the below Gatling dependencies.

Now, we will externalize the baseURL property used in our simulation. For this add the application.properties file under src/test/resources and use ConfigFactory to get access to the properties. The sample simulation is given below.

Now, we will see how to add dynamic data used as part of simulation. For this I am using Gatling’s CSVFeeder. You can get more info on Gatling’s feeders http://gatling.io/docs/2.2.3/session/feeder.html. Add the feeder file under src/test/resources/data. The sample simulation using csv feeder is given below.

The entire project used for this article is available on GitHub.

Gatling Maven Demo

Tagged with: , ,
Posted in Testing

Gatling – Light weight load testing tool

gatling-logo

                                   Gatling is a light weight stress testing tool backed by Scala, Akka and Netty. It  works asynchronously if the under lying HTTP request is non blocking. It uses messages for virtual user simulation than thread per virtual user. Because of this it consumes lesser system resources to run load test. In this article let us see a REST endpoint load testing by following the below steps.

Step 1: Download the Gatling bundle from http://gatling.io/#/resources/download . The folder structure of GATLING_HOME is explained below.

gatling_folder_structure

Step 2: Set GATLING_HOME and JAVA_HOME environment variables and write a sample simulation using Scala. As a java developer you no need to have strong Scala knowledge to write Gatling simulations with Scala. We need to have very basic knowledge. A simulation is given below to test a REST end point.

                     In the above simulation we are ramping up the 1000 users in 10 seconds. Once the simulation script is ready, go to the bin folder and launch the gatling.bat/gatling.sh. The script will run the simulation available under “simulations” folder and generates the reports under results folder.

The sample report is given below.

gatling_performance_stats

In the coming article we will see how to use Gatling maven integration and additional features like feeders, externalizing the properties etc… Till then, Stay Tune!!!

Tagged with: , ,
Posted in Testing
DZone

DZone MVB

Java Code Geeks
Java Code Geeks