Scalable Microservices Using Modern Java-Based Frameworks

The term “microservices” refers to one of the recent software architecture design patterns mostly used by modern software projects such as cloud systems. The microservices design pattern concentrates on the idea of deconstructing large and complex system structure to smaller and simpler independent components. Each of these independent components has a defined role and a set of services to fulfill.The components in microservice-based systems are considered to act independently regardless of residing in one place or being spread across different locations. Each service or, to be more specific, each microservice is expected to be a fully independent sub-system that is totally separated from other sub-systems. The system as a whole is considered to be a network of service interactions fulfilled by the cooperation of independent service endpoints.Achieving such modularity in design and implementation offers numbers of advantageous. The most remarkable advantageous offered by such design pattern is “Scalability.” The scalability for individual components (microservices) up to the system as a whole. The resources could be assigned and tuned more precisely based on the need of each microservice. Moreover, more stability and durability at the service level could be achieved.In respect to the discrete architecture of these sort of systems, whenever a failure happens in any component, the fault is isolated from other parts of the system. The system is considered to be more fault tolerant. The maintainability of the system becomes easier. For instance, if part of the system needs to be updated, there is no need to stop the whole service. The system continues to serve while the update is in progress. Last but not least, the system components can be deployed on different locations. Considering the decentralized approach, the system could benefit from a range of various capabilities that are achieved by following a decentralized system architecture similar to cloud systems architecture.There are a number of challenges in achieving such modularity and independence in design and implementation of such a system. The first and foremost challenge is maintaining overall component coherence while keeping the decentralized paradigm intact. In other words, keep the components decoupled while having the system functioning as a whole and avoiding any data and resource redundancy or lost. The other challenge is maintaining resource management by considering that system components may reside on different locations. Other challenges include the management and security issues of these sort of disparate systems, but those will not be covered in this article.In the real world, modern enterprise development platforms, such as Java Enterprise Edition, provide technologies and tools, helping developers to develop systems based on modern design patterns. The environment provided by Java EE is divided into logical domains called containers. Containers are the infrastructures supporting the modular design and implementation of software components. Each container provides various underlying services such as Transaction, Security, Connectivity, and Messaging to the components it hosts. Java EE standard containers are: Web Containers, EJB Containers, Applet Containers, and Application Client Containers, and each hosts specific type of application.Java application servers are implementations of the Java EE environment. Each application server provides standard Java EE containers plus the services that are offered by each container. In other words, each Java EE application server provides an environment that hosts modular enterprise Java-based applications and provides underlying services and technologies that are required by each deployed application. Such environment helps developers focus on business-oriented problems rather than basic service implementations. Java EE provides technologies that help to maintain modularity in design and implementation of enterprise software components. On a bigger scale, application servers could form a cluster, which provides a seamless environment to host distributed enterprise systems.Considering the features provided by Java EE and the challenges that have been discussed so far, it seems that the challenge regarding the modularity and the coherence of overall system could be achieved by a good design and a set of appropriate tools and technologies, such as Java EE.The other challenge is resource management. Each microservice normally focuses on a single business process or service. Therefore, it consumes specific runtime resources. For instance, in a sample Java EE environment, the microservice that is responsible for the UI service only requires the web container and the corresponding services that the web container provides. In the real world, the Java-based application server that hosts the UI microservice loads additional containers and services that are not required by the UI microservice. Loading these additional containers costs additional resources, such as memory. Be advised that each microservice is considered to be deployed independent of other microservices, therefore it requires a separate runtime environment.To tackle the resource waste challenge, there are a number of possible solutions. One solution could be tweaking the application server settings to load only the required containers. This solution requires enough understanding about the architecture, configuration, and runtime specifications of each application server implementation. Another solution, and the more practical one, is to forget about the application server tweak. The developer has to inspect the technologies (or specifications, in terms of the Java EE ecosystem) required by each microservice, finding the corresponding implementations, doing the configuration, and finally constructing the environment by self.Following any of these solutions distracts the developers from business-oriented problems and engages them with implementation and configuration challenges. This is totally in contrast with the arguments we have made so far.A couple of months ago, I read an article about a Java-based framework named KumuluzEE. KumuluzEE is “A lightweight framework for developing microservices using standard Java EE technologies and migrating existing Java EE applications to microservices,” as mentioned on its site.By automating the deployment and configuration of Java EE-based applications and environments, KumuluzEE helps the developers concentrate on business-oriented problems rather than the implementation. Developers only choose what Java EE-based technologies are required, and KumuluzEE handles the rest.Currently, the following components are supported by KumuluzEE framework as mentioned by 3.1 (Jetty).WebSocket 1.1 (Jetty).JSP 2.3 (Jetty Apache Jasper).EL 3.0 (RI UEL).CDI 1.2 (RI Weld).JPA 2.1 (RI EclipseLink).JAX-RS 2.0 (RI Jersey).JSF 2.2 (RI Mojarra).Bean Validation 1.1 (RI Hibernate validator).JSON-P 1.0 (RI JSONP).To demonstrate the KumuluzEE, a simple modular microservice-based project consists of a Repository (Data) module, a RESTful WebService module for CRUD operations, and a Web portal (UI) module that will be built using the KumuluzEE framework. These modules could be deployed on a single server or deployed across multiple servers. In the following sections, the main features of the framework will be introduced.The main project consists of three modules:Repository module: The module responsible for the data model of the system. It uses JPA (Java Persistence API) technology to persist and retrieve data from the database. This module will be used by other modules.CRUD module: The module that provides a RESTful web service to any backend system or other modules to perform CRUD operations. This module mainly uses JAX-RS (Java API for RESTful Web Services) technology.Web portal module: The UI module of the project that is responsible for retrieving any required dataset and presenting the user with reports, charts, and etc. This module mainly uses JSF (Java Server Faces) technology.This project will be built using maven.  The main project, MainProject, is the container of all modules. For each module (microservice), a new maven project will be created. The MainProject’s POM is as follows: 4.0.0 com.sam MainProject 1.0.0-SNAPSHOT pom WebPortal WebService Respository 2.1.0-SNAPSHOT The element is used for dependency management and compatibility issues between modules.Let’s begin by constructing the Repository module. This module will be used by other modules for data persistence operations. This module is not a standalone service, so the process of creating is pretty much like a normal maven-based project. This project uses Java DB. The Repository module has two dependencies — derbyclient and kumuluzee-jpa-eclipselink. Kumuluzee-jpa-eclipselink is the JPA implementation provided by KumuluzEE. The POM is as follows: 4.0.0 com.sam MainProject 1.0.0-SNAPSHOT Respository jar kumuluzee-jpa-eclipselink ${kumuluzee.version} org.apache.derby derbyclient The Repository module contains the entity class that is the representation of the corresponding table in database and the persistence.xml file. The Project entity will be used to store and retrieve data about some projects in the database. Other modules use Repository module to perform CRUD operations. The entity class:@Entity @Table(name = "PROJECTS") public class Projects implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "ID") private Integer id; @Column(name = "NAME") private String name; @Column(name = "STATUS") private Short status; public Projects() { } public Projects(Integer id) { = id; } public Integer getId() { return id; } public void setId(Integer id) { = id; } public String getName() { return name; } public void setName(String name) { = name; } public Short getStatus() { return status; } public void setStatus(Short status) { this.status = status; } } The persistence.xml file : com.sam.respository.Projects Put persistence.xml inside the “src/main/resources/META-INF” folder and the repository module is ready.Now consider the Web portal module. This module uses the repository module to retrieve information about the available projects in the database and graphically presents them to users. Web portal module uses Java Server Faces technology.As a Java EE developer, to identify the dependencies for any given module, one must have enough knowledge of the Java EE technologies (specifications) that are required by that module. For instance, for the UI module, the following dependencies are identified and have to be set in the POM file: com.sam Respository 1.0.0-SNAPSHOT kumuluzee-core ${kumuluzee.version} kumuluzee-servlet-jetty ${kumuluzee.version} kumuluzee-cdi-weld ${kumuluzee.version} kumuluzee-jsp-jetty ${kumuluzee.version} kumuluzee-el-uel ${kumuluzee.version} kumuluzee-jsf-mojarra ${kumuluzee.version} KumuluzEE supports Jetty as the preferred servlet implementation. Mojarra is also supported by KumuluzEE as the default JSF implementation. Other implementations will be available in the future releases. An important dependency is kumuluzee-core. This is the KumuluzEE core module — the heart of the framework. The core module is responsible for identifying module dependencies, performing relative configurations, bootstrapping, and finally deploying and running the module. This is the magic of KumuluzEE. It frees the developer from any container or technology related configurations and implementations.In the Web portal module, the class acts as the backing bean. MBean has access to the database by use of the persistence context (thanks to the Repository module) and backs a .xhtml page with an ArrayList filled with Projects objects.@Model public class MBean { @PersistenceContext(unitName = "projects") private EntityManager em; private List Projectz = new ArrayList<>(); public List getProjectz() { Projectz = em.createNamedQuery("Projects.findAll") .getResultList(); return Projectz; } }To represent all projects graphically, the index.xhtml file is needed. The projects will be displayed on the index.xhtml page as a data table by use of the JSF h:dataTable tag. The index.xhtml file must be copied into src/main/webapp folder. Projects

Projects Data Table

ID #{} Project name #{} Project Status #{project.status} To finalize the process, the web.xml and bean.xml files must be created and put into the src/main/webapp/WEB-INF and src/main/webapp/META-INF folders respectively.Another important thing to add to the POM is the maven-dependency-plugin. This plugin copies all classes and dependencies in one place that will be used by the KumuluzEE core module to bootstrap the module.Run the maven package command to pack the project and issue the following command to run the -cp target/classes;target/dependency/* issuing this command, KumuluzEE core will identify the dependencies, locate them in the class path, do the appropriate configurations, and bootstrap the module. The module runs on the port 8080 by default. To change the default port on windows, issue the set command first. By opening the address in the browser, the following table will be displayed (considering that we have only two entries in the projects table):Projects Data TableID        Project name     Project Status1             SAM                        12             TOM                       1This is a simple web page to show the UI capability of this module. In the future, more detailed and complex features can be built around this concept.The next module is the CRUD module. This module, with the help of the Repository module, exposes a RESTful web service API providing the CRUD capabilities to other modules. The CRUD module could be used to perform administration tasks such as add/remove or enabling/disabling any existing projects.This RESTful web service provides three methods:insertProject(Projects project): To insert new Projects into the database.getProject(Integer id): To fetch information about the existing projects defined in the database.changeStat(Integer id): To enable/disable existing projects ( Change Stat ).The following dependencies are set for this module: com.sam Respository 1.0.0-SNAPSHOT kumuluzee-core ${kumuluzee.version} kumuluzee-servlet-jetty ${kumuluzee.version} kumuluzee-cdi-weld ${kumuluzee.version} kumuluzee-jax-rs-jersey ${kumuluzee.version} kumuluzee-jsp-jetty ${kumuluzee.version} The class is defined as follows:@Path("/samresource") @RequestScoped public class SamResource { @PersistenceContext(unitName = "projects") private EntityManager entityManager; @GET @Path("project/{id}") @Produces(MediaType.APPLICATION_JSON) public Response getProject(@PathParam("id") Integer id) { Projects projects = entityManager.find(Projects.class, id); if (null != projects) { return Response.ok(projects).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } @GET @Path("project/changestat/{id}") @Produces(MediaType.APPLICATION_JSON) public Response changeStat(@PathParam("id") Integer id) { Projects projects = entityManager.find(Projects.class, id); if (null != projects) { if (projects.getStatus() == 1) { projects.setStatus(((short) 0)); entityManager.getTransaction().begin(); entityManager.merge(projects); entityManager.getTransaction().commit(); } else { projects.setStatus(((short) 1)); entityManager.getTransaction().begin(); entityManager.merge(projects); entityManager.getTransaction().commit(); } return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } @POST @Consumes(MediaType.APPLICATION_JSON) public Response insertProject(Projects project) { try { entityManager.getTransaction().begin(); entityManager.persist(project); entityManager.getTransaction().commit(); return Response.status(Response.Status.CREATED).entity(project).build(); } catch (Exception exception) { System.out.println(exception.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } }Again a bean.xml file needs to be copied in src/main/webapp/META-INF.Running this service is pretty similar to the procedures for the UI module. The CRUD module could be run on the same machine as the UI module, or it could be deployed on a different machine. The point is, these two modules are totally separated from each other, having their own resources and runtime environments. Each of these modules could be maintained and updated independently. Stopping one doesn’t have any impact on the whole service. For instance, the users of the UI module could continue using the system while the web service module is undergoing an update and vice versa.ConclusionTo wrap it up, KumuluzEE is a very good starting point to consider in the design and implementation of microservice-based systems. Other frameworks, such as WildFly Swarm, are also available, they are out of the scope of this article. This article introduced the basic concepts of microservice design patterns and the advantages and challenges in implementing such design patterns. We also covered possible technologies and frameworks used to design and implement microservices, complete with a simple example. Read more

Pokemon Go master says not done with game, hopes for more features

TOKYO Nick Johnson, who claims to be the first person to capture all 145 creatures now available in the "Pokemon Go" mobile gaming phenomenon, says he is not ready to put away his smartphone just yet and hopes for new features. The 28-year-old tech employee from Brooklyn, New York, who refers to himself as the "world-first Pokemon Go master" on his Twitter account, announced last week he had completed his quest after traveling across the globe for the smartphone game. "I'll definitely carry on playing it. There's still a handful of the legendary Pokemon they haven't released yet, so I'm looking forward to when they do that," Johnson told Reuters in an interview in Tokyo on Monday."I'm hoping they add some of the more asked for features like player versus player battling and more direct interaction with other players. It's still a great way to sort of hang out with friends and go outside and it's a good excuse to exercise for me still, so I'll be keeping up the regimen." The game exploded after its introduction last month, with players hitting the streets to capture colorful animated characters. Developed by Niantic and Pokemon Company, in which Japan's Nintendo Co owns a large stake, it marries a classic 20-year old franchise with augmented reality. "For me, the success of Pokemon Go is a testament to the fact that gaming today is really pretty ubiquitous," Johnson said. "Everyone has a smartphone so the idea that gaming is something of a niche industry as it has been in decades past is definitely no longer true."Apart from Pokemon types found everywhere, there are others exclusive to regions. Johnson, who says his tips for other players is to maximize the social aspect of the game and create online and offline networks to find rare creatures, caught his last regional Pokemon in Sydney. (Reporting by Reuters Television; Editing by Tom Heneghan) Read more

Study finds cosmic rays increased heart risks among Apollo astronauts

CAPE CANAVERAL, Fla. Apollo astronauts who ventured to the moon are at five times greater risk of dying from heart disease than shuttle astronauts, U.S. researchers said on Thursday, citing the dangers of cosmic radiation beyond the Earth's magnetic field. The study by researchers at Florida State University and NASA found that three Apollo astronauts, including Neil Armstrong, the first person to walk on the moon, or 43 percent of those studied, died from cardiovascular disease, a finding with implications for future human travel beyond Earth.The research, published in the journal Scientific Reports, was the first to look at the mortality of Apollo astronauts, the only people so far to travel beyond a few hundred miles (km) of Earth.It found that the chief health threat to the Apollo astronauts came from cosmic rays, which are more prevalent and powerful beyond the magnetic bubble that surrounds Earth.NASA disputed the findings, saying it was too early to draw conclusions about the effect of cosmic rays on Apollo astronauts because the current data is limited. The results of the study have implications for the United States and other countries, as well as private companies, such as Elon Musk’s SpaceX, which are planning missions to Mars and other destinations beyond Earth.For the study, the researchers examined the death records of 42 astronauts who flew in space, including seven Apollo veterans, and 35 astronauts who died without ever going into space.They found the Apollo astronauts’ mortality rate from cardiovascular disease was as much as five times higher than for astronauts who never flew, or for those who flew low-altitude missions aboard the space shuttle that orbited a few hundred miles above Earth. A companion study simulated weightlessness and radiation exposure in mice and showed that radiation exposure was far more threatening to the cardiovascular system than other factors, lead scientist Michael Delp said in an interview."What the mouse data show is that deep space radiation is harmful to vascular health," he said. So far, only 24 astronauts have flown beyond Earth’s protective magnetic shield, in missions spanning a four-year period from December 1968 to December 1972.Of those, eight have died, seven of whom were included in the study. The cause of death of the eighth astronaut, Apollo 14's Edgar Mitchell, who died in February 2016, has not been released, so he was excluded from the study, Delp said. Mitchell was the sixth person to walk on the moon.Delp and colleagues are working on a follow-up study that includes more detail on family medical histories, smoking and other factors. (Reporting by Irene Klotz; Editing by Julie Steenhuysen and Peter Cooney) Read more

Verizon to buy Yahoo's core business for $4.8 billion in digital ad push

NEW YORK Verizon Communications Inc said on Monday it would buy Yahoo Inc's core internet properties for $4.83 billion in cash, marking the end of the line for a storied Web pioneer and setting the stage for a big new internet push by the telecom giant.Verizon (VZ.N) will combine Yahoo's (YHOO.O) search, email and messenger assets as well as advertising technology tools with its AOL unit, which it bought last year for $4.4 billion. Verizon, the No. 1 U.S. wireless operator, has been looking to mobile video and advertising for new sources of revenue outside the oversaturated wireless market.The deal came after activist investors led by Starboard Value LP lost faith in Yahoo Chief Executive Officer Marissa Mayer, who was hired in 2012, and forced what became a protracted sale process.Yahoo, founded in 1994, was a dominant player in the early days of the internet, but has long lost its leadership position in internet search and advertising to Google (GOOGL.O>, Facebook (FB.O) and others.Mayer said on a conference call with investors that she planned to stay at Yahoo through the deal's close. Marni Walden, head of product innovation and new business at Verizon, will head the combined internet unit and said no decisions had yet been made on the management team.Verizon could combine data from AOL and Yahoo users in addition to its more than 100 million wireless customers to help advertisers target users based on online behavior and preferences."Yahoo gives us scale that is what is most critical here," said Walden, adding that the company's audience will go from the millions to the billions. "We want to compete and that is the place we need to be."Mayer, in an interview with Reuters, said she still saw a "path to growth" for Yahoo, especially in mobile. "What's exciting about the Verizon transaction is that it brings us back to growth sooner," she said. She said she was "open-minded" about a possible role with the combined companies. Yahoo is still one of the largest properties on the internet, with hundreds of millions of customers using its email, finance and fantasy sports offerings, among others, and a heavily trafficked home page.But Google has a stranglehold on the internet search business and built an industry-leading email service, while Facebook dominates in mobile and social media. Meanwhile, traditional web banner advertising, long Yahoo's strength, has become much less lucrative in the age of mobile and video."It's a decade of mismanagement that has finally ended for Yahoo," said Recon Analytics analyst Roger Entner. "It's the continuation of an extension of Verizon's strategy toward becoming a wireless internet player and a move away from (telecom) regulation for Verizon into an unregulated growth industry."Shares of Verizon dipped 0.4 percent to $55.88, Yahoo fell 2.6 percent to $38.37. FAR BEHIND GOOGLE, FACEBOOKThe integration of Yahoo will not come without challenges. In its latest results, it reported a second-quarter net loss of $439.9 million as it wrote down the value of Tumblr, the microblogging and social media service it acquired in 2013 for $1.1 billion.With AOL and Yahoo, Verizon would still be far behind juggernauts Google and Facebook (FB.O). According to market research firm eMarketer, Yahoo is expected to generate $2.32 billion in net U.S. digital ad sales, while AOL is expected to make $1.3 billion in 2016. Facebook and Google are forecast to deliver sales of $10.3 billion and $24.63 billion, respectively, by the end of this year, according to eMarketer. The Verizon deal would transform Yahoo into a holding company, with a 15 percent stake in Chinese e-commerce company Alibaba Group Holding Ltd (BABA.N) and a 35.5 percent interest in Yahoo Japan Corp (4689.T) as well as Yahoo's convertible notes, certain minority investments and its noncore patents.Yahoo executives said the remaining company is structured to "indefinitely" hold its Yahoo Japan and Alibaba stakes. They are worth about $40 billion based on their market capitalizations, while Yahoo had a market value of about $37.4 billion at Friday's close.Yahoo will continue as an independent company until the deal receives shareholder and regulatory approvals, the companies said. It is expected to close in early 2017. It plans to change its name and become a publicly traded investment company.Yahoo currently has $7.7 billion in cash, in addition to the $4.8 billion it will receive at the close of the deal, which it plans to return to shareholders, Yahoo executives said on the call.Verizon prevailed over rival bidders, including AT&T Inc (T.N); a group led by Quicken Loans founder Dan Gilbert and backed by billionaire Warren Buffett; private equity firm TPG Capital Management LP [TPG.UL]; and a consortium of buyout firms Vector Capital and Sycamore Partners.Under pressure from Starboard, Yahoo launched an auction of its core business in February after shelving plans to spin off its stake in Alibaba. (Additional reporting by Anya George Tharakan in Bengaluru and Deb Todd in San Francisco; Writing by Jonathan Weber; Editing by Bernadette Baum and Jeffrey Benkoe) Read more

Five IoT Hardware Features That Lead to Agile Development

Kurtis McBride and Frank Voisin of Scotland have established a huge 475,000 sq.ft. warehouse as a base for their dream project—an IoT hardware warehouse. As the Internet of Things (IoT) perpetuates business and lifestyle with varied implementations, the hardware systems have to gear themselves to match the imagination of the software solution providers. Here are five IoT hardware features for agile software solutions.1. Wi-Fi, Low-Power RF, Bluetooth, and Ethernet Support ChipA classic example of this feature is the OpenKontrol Gateway by Ciseco that can be used for 24 hours with the incredibly low power of just half a watt. It has built-in XRF radio, SD, RTC, SRAM and XV Wi-Fi module. The Arduino Yun is also a hybrid board with built-in Ethernet and Wi-Fi connectivity features.2. Linux Platform ComputingThe Raspberry Pi gave wings to our imagination of a chip that is built on Linux platform and has USB ports, a HDMI port, a Ethernet port, and a Wi-Fi facility. It has a vast community that makes IoT project development feasible. The Beaglebone Black is a low-cost development platform that runs in the Linux environment and built with ARM Cortex A8 processor. It has built-in Ethernet connectivity features and HDMI port to connect a monitor. It’s strong community makes it the best platform for IoT solution development3. Wi-Fi Module for MicrocontrollersWi-Fi modules give internet connectivity to microcontrollers via UART communication. The ESP8266 comes with TCP/IP protocol stack integrated into its system and these modules further come pre-programmed with AT commands which are easy to plug and play IoT projects. With GPIO pins, specific application devices and sensors can be used for playing specific modules.4. Prototyping PlatformsPrototyping platforms come fully equipped with Ethernet boards and WI-Fi connectivity features that make them essential for working with IoT. Netduino is a famous open source electronics prototyping platform built around STMicro STM32F4 controller and runs in .NET Micro Framework. Some platforms even offer additional features such as UART, I2C, SPI and SD card connectivity. Arudino boards are again familiar devices that come with built-in Internet connectivity and their Ethernet shield can be used for wired connections and the Wi-Fi shield can be used for wireless connection to the internet.5.  Multi-Development PlatformsA single chip for development on multiple platforms. These are definitely open source, community-driven and cost-effective. The UDOO is one such platform that works with Linux, Android, Google ADK 2012, and Arduino. The board provides a flexible environment to work with IoT innovations. HackBerry is also a popular system that works with Android and Linux PC with both WI-Fi and Ethernet.IoT hardware forms the foundation for executing robust software solutions and hence it is essential to IoT development success.Learn more about IoT and its possibilities : IoT Home Automation Solutions With iBeacons Read more

Older Post