Adam Bien's Weblog

Load Balancing Microservices With Docker, nginx and TomEE

nginx can be used as HTTP server and as a load balancer at the same time. In this screencast I used nginx to share the load between two TomEE 7.0.2 instances on Docker.

The Dockerfiles in this screencast were borrowed from: docklands. Binary images are also available from: hub.docker.com/u/airhacks/. The ping healthcheck is directly available from github.com/AdamBien/ping

Also see how HA Proxy can be used to load balance Java EE microservices.

You want to learn more about Java EE and Microservices? Checkout: Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Accidental Spring Evangelism, Rolling Updates, Log Management, Exception Factories, Docker, Queuing Choices or 33rd airhacks.tv

New live viewers record of 191 was set during the 33rd airhacks.tv. The show started with explanation of accidental Spring 5.0 evangelism, then I discussed the questions ranging from central log management, over rolling updates, project specific docker images to queuing choices in microservices and lombok.

Any questions left? Aks now https://gist.github.com/AdamBien/a7a638836c24b9a80133418844a1c2ed .

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Java EE 8 News, Central Logs, Layering, Util, ExceptionFactories, JDBC in Docker, DTOs, Lombok--Or 33rd airhacks.tv

News, opinions and answers for the questions or the 33rd airhacks.tv, Monday, December 5th, 6 pm CET, (checkout past episodes):

  1. Java EE 8 news
  2. Managing logs in central location
  3. About layering: @ApplicationScoped for services?
  4. Why I created an ExceptionFactory--a long time ago.
  5. Util packages and classes
  6. Modal windows in JavaFX and background threads
  7. Managing JDBC drivers in Docker
  8. How to run a DB in a container?
  9. To share or not to share a DB
  10. Managing private docker images
  11. DTOs vs JSON-P for partial data transfer
  12. Microservices: queuing choices -- JMS or not
  13. Rolling updates with Java EE and docker
  14. Dealing with bloat: lombok, IDE or what?

The questions above are going to be answered during the next "Airhacks Q & A" http://airhacks.tv live. You can subscribe to the channel and / or for the next event: http://www.ustream.tv/channel/adambien (both is optional, no registration required to watch this event live).

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

TomEE 7.0.2 Full--Docker Smoke Test

TomEE 7.0.2 Plus (=everything, Java EE 7 full profile, not certified) works well on docker:

  1. 59 MB zip download
  2. Installation is a one-liner in Dockerfile (curl + unzip)
  3. Thin-WAR deployment is supported, what results in fast docker builds (~100ms) and tiny docker images. A single ping.war image takes 9.85 kB on disk
  4. Lightning fast docker image startup: Server startup in 1790 ms (ping WAR deployment included)
  5. Memory footprint is negligible
TomEE 7.0.2 Dockerfiles are available from docklands. Docker images can be directly downloaded from: hub.docker.com/u/airhacks and started with e.g. docker run -d -p 8080:8080 --name tomee-ping airhacks/tomee-ping.

TomEE is production-ready--commercial support is available.

See you at Java EE Workshops at Munich Airport, Terminal and particularly at Java EE 7 Microservices. Is MUC too far? Checkout: javaeemicro.services


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Slicing The Monolith--With Java EE And Docker

Andreas, please introduce yourself

My name is Andreas Enbohm and been working as software developer and consultant for almost 15 years. Since three years ago I’m running my own company assisting various companies with coding, mentoring and methodology improvements. I’d like to call myself a programmer, but often clients defines my role as a technical/programming architect.

What are you building with Java EE?

I’ve ben involved with many types of applications based on Java EE. From eCommerce websites and web portals, to batch processing systems and core backend systems within telecom- and manufacturing industry. Currently I’m involved in refactoring and evolving a quite large self-service portal within the telecom business. The portal could be considered a big monolith with around 50 integrations with various backed systems (databases, IMS systems, CRM systems, etc). We are currently trying to slice the portal into smaller manageable pieces, what could be referred as ”right-sized” service architecture. We don’t really know the number of slices we’re going to end up with, but we think that somewhere around 10-15 services would be a good start. The foundation for these new services are Java EE along with Docker which I have found to be a perfect match! I’m specially keen on using uberjars and for this we utilise WildFly Swarm. With Docker Swarm mode we get the speed we need to deploy these services along with service discovery, failover, clustering, etc. which is nice. However, one big challenge I see is the monitoring and logging when building application this way. Most likely we will need tools to support us here and I’m investigating if the ELK stack (Elasticsearch, Logstash, Kinbana) can solve this problem. And not to forget, we use Swagger to document all our services which I find very easy and just works!

Can you share with us some geeky numbers like e.g. TX per seconds, heap sizes, thinnest WARs etc -- whatever Java EE devs might find interesting.

In this project the number of transaction are fairly low (around a few per seconds) so not much to brag about here. What is more interesting is maybe that the initial code was written in 2001 (using Java 1.3 and JBoss 3) and many old parts is still healthy and used! The portal has during the year gone through major platform- and application server updates. From Java 1.3 to Java 5, 6, 7 and 8 including various JBoss and Apache Tomcat upgrades with basically no or very little code modifications. This really shows that Java is a really long term platform to build upon! When it come to the newer parts the fat/uber jar services are between 40-120 MB and the services built as non-fat ones are ranging from ca 50KB to 10 MB depending amount of libraries included.

Are you happy with Java EE so far? Is Java EE productive?

I have been using Jave EE for 10+ years now. I’m definitely productive and like it. Frameworks like Arquillian makes testing really easy and many application servers are getting really lightweight and easy to manage. However, I have a few concerns about the evolvement of Java EE 8 (and beyond) and feel that in the accelerating pace of software industry, the Jave EE standards might need to speed up a bit. Then there are some parts I’ve been waiting for really long in Java EE such as caching (JSR107) which I really hope to see as part of Java EE 8.

Which application servers, tools or IDEs are you using?

We are currently using Apache Tomcat for the main part of the web portal (JSP pages) and WildFly (incl. Swarm) for the new (micro)-services. Eclipse is the IDE of my choice when developing Java-code and DbVizualizer for database management. Along with Maven, Jenkins, Git and Gerrit I basically got what I need :). There are of course a bunch of other tools I use from time to time but these ones I’m using on a daily basis.

You are using Docker together with Java EE in production. What is your experience so far?

We have been running Docker containers for a couple of month now in production and have not seen any concerns or issues so far. Memory and CPU footprints are low as is the ”overhead” of Docker (if any). Challenges for us are how to gather information (e.g. logs, health status) and how to share persistent data between containers. Also, in the long run, we think some GUI for Docker Swarm mode is needed but have not yet found anyone to support our demands. Shipyard or Rancher might be the way forward but we have yet to decide. But so summarise, I really think Docker, and to be able to treat infrastructure as code along with Java EE, is a really big step forward (kind of a new era) in software development.

How important are standards for you? Does your application depend on application server specific APIs?

For me standards are important. During the years I’ve been using many custom framework/APIs (which has been abandoned or not supported anymore) and this can be a real pain especially from an enterprise application view which might live for many years. Another problem that might occur without standards is vendor lock-in. When using standards, you often minimise these problems which means freedom to switch implementation without touching the actual code. I often avoid usage of any specific/custom APIs, but if needed I try to encapsulate it as much as just possible.

Which Java EE APIs are you using in your products?

The most widely used ones are JSP, Servlet, CDI, EJB, EL (expression language), JAX-RS and JSTL. In the future I believe I will more and more use the MicroProfile (JAX-RS, CDI, JSON-P) baseline for Java EE services.

Take a look at the Java EE 8 APIs. Which of the APIs are most interesting / important to you?

If I had to pick three ones I would go with these:

  • JSR 107 JCACHE (because it is just so fundamental in enterprise development)
  • JSR 375 Security API (because today it is confusing but business critical)
  • JSR 367 (because JSON is such an important exchange format)

Can you share any resources (blogs, etc feel free to promote yourself) with us?

You can follow me on twitter (@enbohm) or see some of my presentations on SlideShare (www.slideshare.net/enbohm) or GitHub (github.com/enbohm). Some of my presentations are internal ones (not shared in public) but you might see me talking at some Java conference soon :)

Andreas, thank you for the inteview!


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

HTTP Status Code Test Service: statustest

statustest is a service which responds with a HTTP status code sent as HTTP status header, e.g.


curl -i -H"status:205" http://localhost:8080/statustest/resources/statuses

responds with:

HTTP/1.1 205 Reset Content
Server: Payara Micro #badassfish
Date: Sun, 27 Nov 2016 09:08:20 GMT


statustest comes as a 4.1 kB WAR and is also available as docker image: docker run -d -p 8080:8080 airhacks/statustest from http://hub.docker.com/u/airhacks.

JAX-RS rulz was tested with statustest, as well as, the other way round. Statustest was also used to test error behaviour of various HTTP JavaScript libraries in reactjs and angular 2 projects.

See you at Java EE Workshops at Munich Airport, Terminal 2, particularly at: Java EE Testing. Is MUC too far? Checkout the online version: javaeetesting.com!


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Custom Matchers, Better Messages: JAX-RS Client Rulz v0.0.4 released

The v0.0.4 release of the JUnit JAX-RS Rules 13kB JAR comes with additional matchers: clientError(), redirection(), informational() and other(), as well as, improved matcher messages, like e.g.


Expected: is 2xx family of successful responses
but: Internal Server Error 500 returned

Installation:


<dependency>
	<groupId>com.airhacks.rulz</groupId>
	<artifactId>jaxrsclient</artifactId>
	<version>v0.0.4</version>
	<scope>test</scope>
</dependency>

Sample usage:


import static com.airhacks.rulz.jaxrsclient.HttpMatchers.successful;

public class JAXRSClientProviderTest {

    @Rule
    public JAXRSClientProvider provider = JAXRSClientProvider.buildWithURI("http://adambien.blog");

    @Test
    public void pingJavaAndVerifyWithMatcher() {

        Response response = (...)
        assertThat(response, is(successful()));
    }


Meet rulz at Java EE 7 Testing and Code Quality workshop at MUC airport.

Junit rules are also explained in the episode "JAX-RS Rules For JUnit" of the online Effective Java EE 7 workshop and episodes "AOP For JUnit - Writing Custom Rules" and "JAX-RS Test Rules" of the online version of Java EE Testing workshop.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

New Java EE Related Docker Images Arrived: Docklands

New Docker images arrived. In addition to the following servers:

Recently also Dockerfiles for: were added.

Docklands Dockerfiles and images are used during the javaeemicro.services online workshop, and during the Java EE Microservices workshop at MUC airport.

The images are directly available from: hub.docker.com/u/airhacks, see usage.

See Docklands in action at Oredev: Slideless Microsevices and Java EE 7 Application Servers vs. Plain "Hello World" screencasts.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Adding And Substracting Path Instances With Java

Method resolve adds Path instances and is useful to create absolute paths. The method relativize substracts Path instances and is useful to remove the root component from the absolute path:


import java.nio.file.Path;
import java.nio.file.Paths;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;


public class PathTest {

    @Test
    public void addPath() {
        Path javaFile = Paths.get("com", "airhacks", "PathsTest.java");
        Path root = Paths.get("src", "main", "java");

        Path absolute = root.resolve(javaFile);

        String expected = "src/main/java/com/airhacks/PathsTest.java";
        String actual = absolute.toString();
        assertThat(actual, is(expected));
    }

    @Test
    public void substractPath() {
        Path absolute = Paths.get("src/main/java/com/airhacks/PathsTest.java");
        Path root = Paths.get("src", "main", "java");

        Path relative = root.relativize(absolute);

	//ignoring the OS-specific separator
        String expected = "com/airhacks/PathsTest.java";
        String actual = relative.toString();
        assertThat(actual, is(expected));
    }

}


See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

How Many "Util"(-ities) Classes Ship With Java 8?

The Util name is considered evil. So, how many "Util*" classes are shipped with Java 8?

Exactly 8 out of 4240. It is remarkable how well most of the Java classes are named. There are only eight exceptions, but most of them could be easily renamed to emphasize their responsibility:

  1. AttributeSetUtilities: extension of AttributeSet functionality from Java's printing library. This either decorates the AttributeSet or validates that. AttributeSetViews or AttributeSetViewProvider would be a better name.
  2. BasicGraphicsUtils: gathers "BasicGraphics" operations. The suffix "Utils" seems to be superfluous.
  3. JTree.DynamicUtilTreeNode: also here the name "Util" does not contribute any valuable information. The name: "Decorator" would probably be more appropriate.
  4. SwingUtilities: a kitchen sink for Swing functionality. The methods for asynchronous UI updates: invokeLater or invokeAndWait are probably the most popular methods.
  5. SynthGraphicsUtils: a kitchen sink for Swing's skinnable look and feel. "Utils" also seems to be superfluos. Just "SynthGraphics" is shorter.
  6. Util: a kitchen sink of CORBA functionality. Comes with the most "interesting" JavaDoc: "Provides utility methods that can be used by stubs and ties to perform common operations."
  7. UtilDelegate: it delegates to the Util above.
  8. Utilities from Swing. The worst possible name for a class. The JavaDoc says: "A collection of methods to deal with various text related activities." I guess "Text" would be a better name.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: Building HTML 5 Applications Without Frameworks, Full week in December 2016: from Java EE 7 Bootstrap, Effective, Architectures over Testing to Microservices
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License