Saturday 8 July 2017

Spring Boot - Learning made easy by simple application

I hope, below mentioned plain-vanilla application would help you to quickly get started with Spring Boot and few supporting technologies/tools. Additionally, you may experiment Docker, Docker Compose and Pivotal Cloud Foundry, if not yet!
I am not writing step by step instructions again here, because README talks a lot @ https://github.com/tirthalpatel/Learning-Spring/tree/master/gs-spring-boot/gs-spring-boot-app

Learning Objectives

Try following with Spring Boot & run app by deploying on local machine / using docker compose / using docker / to pivotal cloud foundry.
  • Spring Boot + Spring Web (MVC and REST) + Thymeleaf (Template engine)
  • Spring Boot + Swagger UI (easily visualize and interact with the API’s resources)
  • Spring Boot + Properties customization
  • Spring Boot + Spring Data JPA + H2 Database + FlywayDB (deal with RDBMS)
  • Spring Boot + Spring Data REST + HAL browser (easy to build hypermedia-driven REST web services)
  • Spring Boot + Spring Data Redis (publish and subscribe to messages sent via Redis)
  • Spring Boot + Production-ready features of Spring Boot Actuator
  • Spring Boot + Hawtio (a lightweight web console to monitor and manage application)
  • Spring Boot + Developer Tools (for automatic restart, livereload support..)
  • Spring Boot + Lombok (a java annotation library to reduce boilerplate code)
  • Spring Boot + Testing (JUnit, Hemcrest, AssertJ, Mockito, Spring Test)

How to run the application?

Refer README for instructions to build, deploy and run application using below options. You must need Redis server for option 1, 2 and 3. For option 4, you don't need to set up Redis explicitly, as you can leverage Redis service from Pivotal CF marketplace.
  1. Using maven on local machine
  2. Using Docker Compose
  3. Using Docker
  4. Deploying to Pivotal Cloud Foundry (Cloud PaaS)

Sunday 11 June 2017

Java power tools series - Executive diagram

I hope, you have already read "Preface" of my java power tools series.

In this blog, I just thought to publish my one of old mind mapping diagrams (not updated in last 2 years). I think, following java tools classification view should be effective and useful to others' for quick reference.

(Right click the image - Open in New Window - Zoom it)


Please share your experience in comment, if you have something to add / update with respect to following outlined java tools blueprint.


Disclaimer

I am not biased to particular free or commercial tools, rather my objective is about sharing my own experience on set of tools. 

Sunday 30 April 2017

WireMock - A simple standalone HTTP server for service virtualization

I hope, you have already read "Preface" of my java power tools series. In this post, I intend to introduce WireMock tool.

Straight from the horse's mouth

  • Mock your APIs for fast, robust and comprehensive testing using WireMock (a simulator for HTTP-based APIs /  service virtualization tool / mock server)
  • Enables you to stay productive when an API you depend on doesn't exist or isn't complete
  • Supports testing of edge cases and failure modes that the real API won't reliably produce
  • Features = HTTP response stubbing, request verification, proxy/intercept, record/playback of stubs and fault injection
  • Flexible deployment options - run it from within your Java application, JUnit test, Servlet container or as a standalone process
  • Powerful Request Matching - Match request URLs, methods, headers cookies and bodies using a wide variety of strategies & first class support for JSON and XML
  • Record and Playback - Get up and running quickly by capturing traffic to and from an existing API

My Personal Feedback

I witnessed that WireMock's is extremely easy to setup and harness.  This tool can benefit appreciably in MicroServices Architecture. Let me explain two scenarios, where I could take advantage of WireMock.

(1) Create quick prototypes of REST APIs

Many times, services are not implemented by REST server apps or made available by external vendors. Still, there is a pressing need to develop REST client app beforehand, may be for demo purpose or meeting deliverable goals or due to any other business need. Well, WireMock can help here to create prototypes of agreed APIs quickly, which can be consume by client apps even without realizing these are stubbed APIs instead of real. See running wiremock as a standalone process option.



(2) Record real external services and playback

At times, client app needs to consume third-party or external services over internet or network. However, there are frequent connectivity issues or high latency problem or only limited requests are supported per day due to chargeable services, specifically while accessing these services in Development. Obviously, this may result in high developer productivity loss. Well, WireMock has unique ability to record real services (requests and responses) without a need of single line of coding and playback those in even offline mode automatically. WireMock's this record/playback of stubs feature can greatly boost developer productivity. See record and playback option.


Other scenarios you might want to consider WireMock for:
  • Testing mobile apps that depend on third-party REST APIs
  • Injecting otherwise hard-to-create errors in 3rd party services
  • Any unit testing of code that depends on a web service

All in all, WireMock is a Java-based flexible library with a JSON API that can be used to virtualize, mock, and stub web services.

Try WireMock Practically

Now let's understand fundamental ability of WireMock by running it as a standalone HTTP server and stubbing web services. Let's see practically how effortless it is.

ABC of WireMock standalone server


To POST data to WireMock's REST endpoint (i.e. http://localhost:9999/__admin/), you can use curl or postman tool or any other choice of tool.

  • Start wiremock as a standalone server:  java -jar wiremock-standalone-2.6.0.jar --port 9999 --verbose true
  • This would create "__files" and "mappings" folders (in the same folder where wiremock jar exists) to store stubbed services. To see what all service stubs exist on WireMock server (within "__files" and "mappings" folders), open admin console in browser: http://localhost:9999/__admin/
  • To stop wiremock, just kill the process or post a request with an empty body to this REST endpoint: http://localhost:9999/__admin/shutdown
  • For more detail, see @ http://wiremock.org/docs/running-standalone/.


Stubbing Services / Create REST APIs Prototypes

A core feature of WireMock is the ability to return canned HTTP responses for requests matching criteria. These criteria can be defined in terms of URL, headers and body content.


Record external services and Playback

WireMock has the ability to create stub mappings by recording them while you send requests. This can be used to quickly capture a collection of responses from a real service then use them offline in your tests.
For Example, run this command to record and playback Github Developer APIs:

For any requested REST service request (i.e. http://localhost:9999/users/tirthalpatel), first of all WireMock would check, if corresponding stub mapping exists in "mappings" folder or not. If existing, then don't hit real service rather serve recorded data from "mappings" and "__files" folders. If not existing, then WireMock calls external real service (i.e. https://api.github.com/users/tirthalpatel) followed by records stub mapping followed by returns response to the client. That means, we can expect WireMock to playback all recorded stub mappings even if internet is unavailable.



The above explained and few more examples, you can find @ https://github.com/tirthalpatel/Learning-Tools/tree/master/gs-wiremock


Also See

Disclaimer

I am not biased to particular free or commercial tools, rather my objective is about sharing my own experience on set of tools. 

Saturday 14 January 2017

Say "Hello" to Elastic Stack and How to get started with Elasticsearch 5.x?

Last Saturday, I got chance to attend "Log Aggregation and Analysis using Elastic Stack" meetup, organized at Ishi Systems, Ahmedabad. Thanks to Dhaval Mehta, speaker of this meetup, who imparted excellent presentation of this topic along with practical demo.  My key Learning from this meetup is: To accomplish common use cases like Log aggregation and analysis, it's all about investing initial efforts for installation and configuration of open source Elastic Stack (Beats, Logstash, Elasticsearch and Kibana). Apparently, no development efforts are required.


Then, after exploring and playing with Elastic Stack for few hours, I thought to write this post today. In my view, with the release of Elastic Stack 5.0.0 in October 2016, now getting started with Elasticsearch and associated products is a piece of cake.

Everything (Elasticsearch, Kibana, Beats, Logstash, and X-Pack) is well aligned, tested and released together in Elastic Stack. What does it mean to newbie? Well, earlier individuals were responsible to choose, integrate and test best suitable version of products or plugings to accomplish overall Elasticsearch based solution. For example, which plugin to use with Elasticsearch for monitoring, mavel or head plugin? Which version of Logstash or of any other supported tooling will work impeccably with Elasticsearch 1.x or Elasticsearch 2.x? Now, with Elastic Stack version 5.0 onwards, one gets production ready harmonized products. That means, overall experience to deploy and manage Elastic Stack is anticipated to be stable and more graceful than earlier. 

The Open Source Elastic Stack = Reliably and securely take data from any source, in any format, and  search, analyze, and visualize it in real time. Be aware, X-Pack is commercial offering.
Products
Description (see for detail)
Essential Information
Visualize your data and navigate the Elastic Stack using Kibana.
Kibana gives shape to your data and is the extensible user interface for configuring and managing all aspects of the Elastic Stack.
  • An open source analytics and visualization platform designed to work with Elasticsearch. Offers easy to use UI for performing advanced data analysis and visualization of data in variety of charts, tables, maps.
  • What if some exceptional use case is not supported out-of-the-box in Kibana? - Well, need to consider Kibana plugin development using "Node, Javascript, HTML and CSS".
Store, search, and analyze your data using Elasticsearch.
Elasticsearch is a distributed, JSON-based search and analytics engine, designed for horizontal scalability, reliability, and easy management.
  • Elasticsearch is distributed document store and search server, which offers standard RESTful APIs and JSON to interact with it via client libraries in many languages such as Java, Python, .NET, Groovy, etc. In case of Java application, one may consider Spring Data Elasticsearch for interacting with Elasticsearch.
  • Typical use cases of Elasticsearch are: (1) Elasticsearch as the primary back end (document-oriented NoSQL data store with near real-time search and analytics capabilities) for an application (2) System using another database as the "source of truth", and added Elasticsearch to an existing system to offer enterprise search (3) Using Elasticsearch with existing tools, such as ELK as a large-scale logging framework, now branded as Elastic Stack.
Centralize, Transform & Stash Your Data using Logstash.
Logstash is an open source, server-side data processing pipeline that ingests data from a multitude of sources simultaneously, transforms it, and then sends it to your favorite “stash.” It has a rich, extensible plugin ecosystem and strong Elasticsearch synergy.
  • Logstash ecosystem already has 200+ plugins to mix, match, and orchestrate different inputs, filters, and outputs to work in pipeline harmony. (see support matrix)
  • What if ready-to-use-plugin is not available for specific custom need? Well, consider to develop a custom Logstash plugin using "Ruby".
Lightweight Data Shippers.
Beats is the platform for single-purpose data shippers. They install as lightweight agents and send data from hundreds or thousands of machines to Logstash or Elasticsearch.
  • The Beats family mainly includes (1) Filebeat (for real-time insight into log data) (2) Metricbeat (to ship and analyze metrics) (3) Packetbeat (to analyze network packet data) (4) Winlogbeat (to analyze windows event logs). Additionally, there are numerous community beats are available.
  • What if ready-to-use Beat is not available for specific custom need? Well, consider to develop a custom Beat using "Go".
Security (formerly Shield), Altering (via Watcher), Monitoring (formerly Marvel), Graph and Reporting using X-Pack
X-Pack has features built and maintained by Elastic engineers that integrate across the Elastic Stack.

Also, available as Elastic Cloud service offering.

How to get started with Elasticsearch 5.x?

First of all, understand basic concepts of Elasticsearch (cluster, node, index, type, document, shards and replicas) + see slide @ Elasticsearch as a search alternative to a relational database + watch webcast @ Your Data, Your Search, Elasticsearch.

Try fundamental Elasticsearch REST APIs for exploring cluster, modifying your data and explore your data practically. For this, mainly two options available:
  • Install Elasticsearch on your local machine
  • Leverage 14 days trial of Elastic Cloud

Option 1: Install Elasticsearch on your local machine

For learning Elasticsearch for long term interest, installing it locally could be good option. Here, you have multiple options.
  1. Just install Elasticsearch and try REST APIs using your choice of REST client tool such as postman, curl, etc.
  2. Use Elasticsearch docker image, if you are fan of docker.
  3. Install Elasticsearch -> Kibana -> X-Pack. Personally, I prefer this option.

If you install Elasticsearch, Kibana and X-Pack, then login Kibana (http://localhost:5601/) using default username/password (elastic / changeme). Then, use "Dev Tools" to play with Elasticsearch REST APIs & see how Elasticsearch clusters, nodes and indices react in "Monitoring" section.



Option 2: Leverage 14 days trial of Elastic Cloud

If you don't wish to install Elasticsearch locally, may be because you are just interested in exploring fundamentals, then just go for leveraging Elastic Cloud to get started with it.
  1. Sign up to Elastic Cloud and Login
  2. Create new cluster and preserve the password which you get at the end
  3. Open Kibana UI and login using the password which you got in previous step, and use "Dev Tools" section to play with Elasticsearch REST APIs



Disclaimer

I am not biased to promote any particular free or commercial products offering, rather my objective is limited to share my own experience.