Reader small image

You're reading from  JBoss: Developer's Guide

Product typeBook
Published inAug 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781788296199
Edition1st Edition
Languages
Right arrow
Author (1)
Elvadas Nono Woguia
Elvadas Nono Woguia
author image
Elvadas Nono Woguia

Elvadas Nono Woguia is a software engineer, consultant and Open Source tech enthusiast living in Paris area. Elvadas studied computer sciences at Ecole Polytechnique Yaounde in Cameroon and also hold a Specialized Master in IT systems Management from Ecole Centrale Paris. He has been working for 10 years now in EMEA IT industry for various companies and customers and currently employed by Red Hat as Middleware and PAAS consultant. Elvadas is Certified Oracle Web Component Developer Expert , Certified Red Hat Platform As a Service Delivery Specialist. He currently helps Red Hat customers on their open source journey to design modern and scalable architectures; build customize and integrate various Middleware and cloud technologies and products around JBoss and Openshift ecosystems. In his free time, Elvadas loves playing and watching soccer. He shared tech posts with the open source community on his blog on the red hat developers website. He cares about care about humanitarian causes ; he founded and worked to bring peace and light among the needy his charity UrgenceSolidaires.
Read more about Elvadas Nono Woguia

Right arrow

Custom Web Deployment using Undertow and Swarm

Undertow is the default web server included in the WildFly Application server. Undertow replaced the JBoss web server from WildFly 8. In Chapter 2, Developing and Hosting Scalable Web Applications, users implicitly used the embedded version of Undertow in JBoss AS to host an application. This chapter is about handling custom deployment scenarios by embedding Undertow in Java applications. The user will also learn how to set up highly available deployments and build microservices with Undertow.
This chapters is organized around the following topics:

  • Undertow--purpose and architecture
  • Undertow request life cycle and error handling.
  • Microservices with the Undertow API
  • Undertow reverse proxy and load balancing features
  • Configuring an Undertow subsystem in WildFly
  • Using WildFly-Swarm to package Java EE applications for microservices...

Undertow - purpose and architecture

Undertow is a powerful and lightweight web server written in Java, supporting both blocking and non blocking I/O. With a non-blocking programming model, when the client sends a request to a server, most of the time it will be handled asynchronously and in two steps.

An asynchronous call returns immediately, without waiting for the I/O to complete. The completion of the I/O is later communicated to the caller through the triggering of a callback routine that is executed outside the linear control flow of the application.

Undertow relies on NIO to provide a powerful API, enabling users to build high-performance deployments in a composition architecture way. With Undertow, users can build a web server by combining small single-purpose handlers. Undertow supports Servlet 3.1, Websockets (JSR-356), and reverse proxy.

...

Microservices with Undertow

Your only limit is your imagination.

In the earlier sections, we discovered the Undertow architecture and how to quickly build simple web servers, file browsers, and reverse proxy. In the following section, we are interested in how to build complete microservices with the Undertow Builder API, and how to connect Undertow with the open source ecosystem--JPA, CDI, and RESTEasy--to build a simple REST API.

Reading money transfer details

As seen in previous sections, the Undertow API facilitates application development without standard Java EE containers, making it a good candidate for creating microservices. In the following section, we will cover a practical use case on how to create a full microservice...

Load balancing with an Undertow subsystem

Considering the fact that we have two running undertow instances, we will configure a WildFly application server Undertow subsystem to act as a load balancer in the following section.
Start two instances of the beosbank-undertow-service project using the following:

$mvn exec:java -Dundertow.port=7071
$mvn exec:java -Dundertow.port=7072

Download, install, and run a WildFly application server in standalone mode:

unzip $HOME/Downloads/wildfly-11.0.0.Alpha1.zip
cd wildfly-11.0.0.Alpha1/bin
$ ./standalone.sh

WildFly is now running and listening on port 9990; connect to the server using jboss-cli, as follows:

./jboss-cli.sh --connect

For Undertow to act as a static load balancer behind a set of backend systems, we must register remote socket bindings for these backend systems:

[standalone@localhost:9990 /] /socket-binding-group=standard-sockets...

Innovative microservice packaging with WildFly Swarm

WildFly Swarm is a WildFly extension project that aims to facilitate Java EE applications with minimum dependencies in the form of an executable JAR, called Uberjar or flat-jar. This JAR is deployed on an embedded container derived from the WildFly application server. WildFly Swarm is an initiative around the microprofile that aims to optimize Enterprise Java for a microservices architecture.
To create a flat-jar from a web application, you simply have to use the WildFly Swarm Maven plugin to package your web application:

<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>...

Summary

Undertow is a lightweight and powerful web server written in Java, uses non-blocking IO, and also, users can quickly set up fast applications. Using the Undertow Builder API, users can create custom applications that integrate perfectly with core Java and open source technologies. In the current chapter, we covered Undertow architecture and the API through practical samples; we also saw how to create and deploy a microservice application with Undertow, CDI and JPA. Users can take advantage of the Undertow features from the WildFly application server. An Undertow subsystem can be set up to act as static or dynamic load balancer. Undertow perfectly supports the mod_cluster and HTTP2 protocols. Undertow can be a good candidate to start a microservice journey, but for the existing JEE applications, migration to a microprofile can be facilitated by the WildFly-Swarm project...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
JBoss: Developer's Guide
Published in: Aug 2017Publisher: PacktISBN-13: 9781788296199
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Elvadas Nono Woguia

Elvadas Nono Woguia is a software engineer, consultant and Open Source tech enthusiast living in Paris area. Elvadas studied computer sciences at Ecole Polytechnique Yaounde in Cameroon and also hold a Specialized Master in IT systems Management from Ecole Centrale Paris. He has been working for 10 years now in EMEA IT industry for various companies and customers and currently employed by Red Hat as Middleware and PAAS consultant. Elvadas is Certified Oracle Web Component Developer Expert , Certified Red Hat Platform As a Service Delivery Specialist. He currently helps Red Hat customers on their open source journey to design modern and scalable architectures; build customize and integrate various Middleware and cloud technologies and products around JBoss and Openshift ecosystems. In his free time, Elvadas loves playing and watching soccer. He shared tech posts with the open source community on his blog on the red hat developers website. He cares about care about humanitarian causes ; he founded and worked to bring peace and light among the needy his charity UrgenceSolidaires.
Read more about Elvadas Nono Woguia