One of the common questions asked related to WebSockets is how to how to load balance them. This Tech Tip will explain that for WildFly and JBoss EAP 6.3.

First, what are the main components ?

At least Apache HTTPD 2.4.5 is required. Now HTTPD binaries are not available for Mac but fortunately compiling instructions are explained clearly in Tech Tip #45.

mod_proxy_wstunnel is an Apache module that provides support for tunneling of Web Socket connections to a backend Web Sockets server, such as WildFly or JBoss EAP. It is a support module to mod_proxy that provide support for a number of popular protocols as well as several different load balancing algorithms. The connection is automagically upgraded to a WebSocket connection. And all the modules are already included in the modules directory.

mod_proxy_balancer module is required that provides load balancing for HTTP and other protocols.

Proxy is a container for proxied resources and is creating a load balancing group in this case using balancer directive. BalancerMember adds a member to this load balancing group. ProxyPass is a standard directive that maps remote servers running on different ports into the space of the local server. In this case, WildFly is started in domain mode and so starts two instances on port 8080 and 8230. Both of these instances are mapped to localhost:80, which is where Apache HTTPD is running by default.

The deployed chat sample is now accessible at localhost:8080/chat (first instance in the managed domain), localhost:8230/chat (second WildFly instance in the managed domain), and localhost/chat (via Apache HTTPD).

Now even if you kill one of the WildFly instances, the other instance will continue to serve the client. Note, this only gives application availability as there is no session failover in this.

This was also verified on JBoss EAP 6.3 and there are a few differences:

An important point to understand is that there is no concept of “sticky sessions” in WebSocket as, unlike HTTP, there is a direct and “permanent” connection between the client and the server in this case.

WildFly instances can be easily started in OpenShift. Tech Tip #7 shows how to spin up an instance of WildFly in OpenShift. Tech Tip #21 explained how to get started using JBoss Tools.

Now this WildFly instance is started with the stock configuration.xml. However some times you may want to configure the containers or specify additional configuration information in this file. This Tech Tip will show you how to do that.

On the application page, clone the workspace associated with this application. The command will look something like:

1

2

3

git clonessh://XXXXXXXXXX@test-milestogo.rhcloud.com/~/git/test.git/

This workspace has .openshift/standalone.xml file. Edit this file to meet your need. For example, if you want to use Infinispan as a persistency solution in standalone mode, then you’ll add the following code fragment:

Tipi.camp provides a simple campground management software and targets 25,000+ independent campgrounds all over Europe. It provides a customer-friendly booking-portal and a RESTful API for partners to integrate. The project was conceived in September 2013 when Christoph returned from vacation, disappointed because of the missed booking for their tent. And now he has created a new solution connecting campers and campgrounds with each other.

The website offers a SaaS where campgrounds can register their camp sites and campers can look at the availability of these campgrounds, check out their calendar, pick a site and make a reservation. It is also available for on-site installation if you prefer running it on your domain. Think of it as koa.com, but available to all the independent campgrounds and much more modern 😉

Websites of smaller campgrounds are typically characterized by low data maintenance and absence of a booking possibility. tipi.camp has advantages:

Easy-to-use portal for campground owners and campers

Campground owner administrate and book his sites independently

Customer data management

External sales channels, for example booking.com, can be connected to sell the log cabins

RESTful API it is also possible to handle larger individual installations

Campgrounds get their own portal, reservations, channel management, email and much more for €1/day if they are located in Europe or $1/day if they are in US. Each campground with an Internet connection and browser (whether computer or iPad) can use the software.

In terms of the overall flow, campground owner register their campground with tipi.camp. Traveler checks out the calendar and books the campground using the responsive portal.

Check out the welcome page:

Campers can search through the available camps and then look at the calendar of a particular camp:

Pick a particular site on the campground:

And then checkout to make the payment:

This website is built using Java EE 7:

Here is a brief description of the technology stack:

Presentation

JavaServer Faces + Expression Language. Different templates are used for desktop and iPad apps. JSF Template Library might be used to provide a fully customized portal for the campground owners later.

One of my blogs needed Apache HTTPD 2.4.x on Mac but quickly realized that the binaries are available only for Netware and Win32. Even the build instructions were only for RPM-based systems. So I downloaded the source code and started building it.

Complete compile instructions are explained here. However there were some issues on Mavericks and so decided to document it.

Java EE 7 was released last year, Java EE 8 preparations have already started, so what tempts me to write a blog about Java EE 6 ?

A few reasons …

Even though Java EE 5 was the first version where some of the specs were updated to simplify the platform, Java EE 6 is where higher productivity became the primary focus and kicked into high gear.

All commercially available application servers are still Java EE 6 compliant.

Java EE 7 is pretty cool and provide an awesome bunch of new technologies like WebSocket, Batch, JSON, and Concurrency. But customers are still sticking around with older version of the platform because these applications, servers, and environments cannot change overnight.

So if you are looking for a real-world Java EE 6 sample application that:

Use Eclipse for building a Java EE 6 application

Build persistence layer with JPA2 and Bean Validation

Build business services with JAX-RS

Building the User Interface with HTML5

Building Administration UI with JBoss Forge

Building statistics dashboard using HTML5 and JavaScript

Hybrid mobile version of the app using Apache Cordova

In addition, it also shows:

Deploy your application on a local instance or a remote instance running in OpenShift

Run tests against your JBoss instance

Ticket Monster is your ultimate source. It not only shows how the key Java EE 6 technologies can be used together but also integrate jQuery, HTML5, and mobile version of the application as well.

Various RDBMSs are the de-facto standard for persistency. Using them is such a safe bet by architects that I dare say they are used in too many places nowadays. To fight against this, I have recently been exploring with alternative persistency options, like graph databases. This time I played with Infinispan.

In case you are not familiar with Infinispan, or distributed key/value data stores in general, you could think of it as a HashMap on steroids. Most essentially, the map is shared among all your cluster nodes. With clustering you can gain huge size, blazing fast access and redundancy, depending on how you configure it. There are several products that compete with Infinispan, like Ehcache and Hazelcast from OS world and Oracle Coherence from the commercial side.

Actually, Infinispan is a technology that you might have used without noticing it at all. For example high availability features of Wildfly heavily rely on Infinispan caches. It is also often used as a second level cache for ORM libraries. But it can also be used directly as a persistency library as such.

Why would you consider it as your persistency solution:

It is a lightning fast in-memory data storage

The stored value can be any serializable object, no complex mapping libraries needed

It is built from the ground up for a clustered environment – your data is safer and faster to access. It is very easy for horizontal scaling

It has multiple optional cache store alternatives, for writing the state to e.g. disk for cluster wide reboots

Not all data needs to be stored forever, Infinispan has built-in sophisticated evict rules

Possibility to use transactional access for ACID changes

Sounds pretty amazing, doesn’t it? And it sure is for certain use cases, but all technologies have their weaknesses and so do key/value data stores. When comparing to RDBMSs, the largest drawback is with relations to other entities. You’ll have to come up with a strategy for how to store references to other entities and searching based on related features must also be tackled. If you end up wondering these questions, be sure to check if Hibernate OGM could help you.

Also, doing some analysis on the data can be considered simpler, or at least more familiar, with traditional SQL queries. Especially if you end up having a lot of data, distributed on multiple nodes, you’ll have to learn the basics of MapReduce programming model to do any non trivial queries.

Using Infinispan in a web application

Although Infinispan is not tied to Wildfly, I decided to base my experiments on Wildfly. Its built in version is available for web applications, if you explicitly request it. The easiest method to do this is to add the following MANIFEST.MF entry to your war file. If you don’t want to spoil your project with obsolete files, just add it using a small war plugin config.

1

2

3

4

Dependencies:org.infinispan export

Naturally you’ll still want to add an Infinispan dependency to your application, but you can leave it to provided. Be sure to use the same version provided by your server, in Wildlfy 8, Infinispan version is 6.0.2. In a Maven project, add this kind of dependency declaration:

1

2

3

4

5

6

7

8

9

10

&lt;dependency&gt;

&lt;groupId&gt;org.infinispan&lt;/groupId&gt;

&lt;artifactId&gt;infinispan-core&lt;/artifactId&gt;

&lt;version&gt;6.0.2.Final&lt;/version&gt;

&lt;!--Provided aswe usethe Infinispan provided by Wildfly--&gt;

&lt;scope&gt;provided&lt;/scope&gt;

&lt;/dependency&gt;

Before accessing Infinispan “caches”, you need to configure them. There are both programmatic and xml configurations available. With Wildfly, it is most natural to configure the Infinispan data store right into the server config. The “right” config file depends on how you are launching your Wildfly server. If you are testing clustering locally, you probably want to add something like this into your domain.xml, under the <subsystem xmlns="urn:jboss:domain:infinispan:2.0"> section.

1

2

3

4

5

6

7

&lt;cache-container name="myCache"default-cache="cachedb"&gt;

&lt;transport lock-timeout="60000"/&gt;

&lt;replicated-cache name="cachedb"batching="true"mode="SYNC"/&gt;

&lt;/cache-container&gt;

Note that with this config, the data is only stored within the memory of cluster nodes. To learn how to tweak cache settings or to set up disk “backup”, refer to the extensive Infinispan documentation.

To remove all Infinispan references from the UI code, I created an EJB that does all the data access. There I inject the CacheContainer provided by Wildfly and fetch the default cache in an init method.

1

2

3

4

5

6

7

8

9

10

11

@Resource(lookup="java:jboss/infinispan/container/myCache")

CacheContainer cc;

Map&lt;String,MyEntity&gt;cache;

@PostConstruct

voidinit(){

this.cache=cc.getCache();

}

I guess you are already wondering it: yes, the Map is the very familiar java.util.Map interface and the rest of the implementation is trivial to any Java developer. Infinispan caches extend the basic Map interface, but in case you need some more advanced features, you can also use Cache or AdvancedCache types.

The MyEntity in the previous code snippet is just a very simple POJO I created for the example. With Vaadin CDI usage, I can then inject the EJB to my UI class and do pretty much anything with it. The actual Vaadin code has no special tricks, just normal CDI spiced Vaadin code.

Based on this exercise, would I use Infinispan directly for persistency in my next project? Probably not, but for certain apps, without hesitation. I can also imagine certain hybrid models where some of the data is only in an Infinispan cache and some in traditional RDBMS, naturally behind ORM, taking the best of both worlds.

We’ll also be using Infinispan in our upcoming joint webinar with Arun Gupta from RedHat on September 8th, 2014. There we’ll show you a simple Vaadin application and how easy it can be to cluster it using Wildfly.

Gavin King (creator of Hibernate and CDI) and Stéphane Épardaud will be touring the USA East coast JUGs in October. At each venue, they will explain what Ceylon is, and why you will want to use it for your next production applications. The talks will be aimed at people who have never heard of Ceylon, or who have heard about it but want to know more. At the end of the evening you will be up to date with all that Ceylon is and has to offer.

Mike Piech (@mpiech), GM of JBoss Middleware Business Unit explains them in a succinct video:

Its structured in three buckets:

Accelerate – Building things faster

JBoss Enterprise Application Platform provides an innovative modular, cloud-ready architecture, powerful management and automation, and world class developer productivity. It is Java™ EE 6 certified and features powerful yet flexible management, improved performance and scalability, and many new features to maximize developer productivity.

Red Hat JBoss Web Server is the only enterprise-class web server solution you need for large-scale websites and lightweight web applications. It provides a more secure and a more stable environment of open source web software, like Apache and Tomcat.

Red Hat JBoss Developer Studio provides superior support for your entire development lifecycle. It includes a broad set of tooling capabilities and support for multiple programming models and frameworks, including Java™ Enterprise Edition 6, HTML5, and many other popular technologies. It provides developer choice in supporting multiple JVMs, productivity with Maven, and in testing with Arquillian. It is fully tested and certified to ensure that all its plug-ins, runtime components, and their dependencies are compatible with each other.

Red Hat JBoss Fuse Service Works is a platform that creates reusable, changeable, and flexible business services that hide the complexity of connecting to different applications in your enterprise. It sets the stage for faster and easier cloud applications, mobile applications, and business process development projects.

Red Hat JBoss Data Virtualization is a lean, virtual data integration solution that unlocks trapped data and delivers it as easily consumable, unified, and actionable information. JBoss Data Virtualization makes data spread across physically diverse systems—such as multiple databases, XML files, and Hadoop systems—appear as a set of tables in a local database.

Red Hat JBoss BPM Suite is a comprehensive platform for business process management. It includes all the business rules and complex event processing (CEP) capabilities of Red Hat JBoss BRMS [business rules management system], along with advanced tools and runtime support for Business Process Model and Notation v2.0 (BPMN2)-compliant business processes.

Alexis Hassler (@alexishassler) is a software developer, specialized in Java and Java EE. He is using JBoss since version 2.0, more than twelve years ago. His business is to code for other companies or help them to improve the way they develop and deploy Java applications. He is co-leader of LyonJUG and helps to organize Mix-IT, an annual conference in Lyon.

Q. You recently concluded a 4-day WildFly administration course. Tell us more about that.A. This course will help you understand the operation, configuration principles of WildFly. The core of the course is 3 days long. It deals with installation, deployment, administration tools, security and tuning. The forth day is on clustering and is optional. The recently concluded session was the first one and was conducted on-site in Brussels.

Q. Who is this course targeted for ?A. The course is designed for application server administrators. But it is useful for developers and software architects too. In fact, it is useful for anybody who have to work with WildFly.

Q. How much of this course would be relevant for JBoss EAP users/customers ?A. JBoss EAP 6 is based on JBoss AS 7, but a lot of administration features of the latest EAP has been added in WildFly 8. So if you have EAP 6.2 or 6.3, this course will match ~ 80%. If you have an older EAP, a JBoss AS 7 course would be better (http://www.sewatech.fr/formation-jboss-7.html). JBoss EAP users is not the main target of this course. RedHat has some great courses on JBoss Middleware Development and JBoss Middleware Administration.

Jboss-cli is the most useful one. It allow an admin to automate the whole setup his application server. The HTTP API is great too, as it allow to make custom tools in any language. For example, you can build your own simplified admin console in pure JavaScript. I don’t really like the Java API because, it’s a detyped API and it doesn’t fit with a compiled-time typed language. Maybe a Groovy guy could make a nice DSL on top of it. All in one, the greatest thing is that the different tools are really consistent : same data and same logic to manipulate these data. If you learn jboss-cli, it’s really easy to understand the HTTP API.

Q. What tips would you give for users coming new to WildFly ?A. If you know JBoss AS 7, it will be easy. WildFly 8 is just the next version. Read the changelog and everything will be fne. If you know older versions of JBoss AS, forget everything you know, and start from the beginning with a good book. If you know Tomcat, be prepared to discover the power to “fly”. And for everybody, learn the CLI tool.

Q. Which application servers developers should choose, for both development and deployment ?A. It mainly depends on what you want to do. Tomcat can be great too, because it’s really simple. When it comes with Java EE, TomEE is a very nice application server but lacks of administration tools. For Glassfish, we will see with the next versions if the current quality is maintained or if it comes back to a simple RI software. So, OK, WildFly is my favorite choice : great module system, great admin tools and great community.

This release brings continued progress on the road to making EAP the most manageable and secure Java EE 6-compliant Application Server for traditional and cloud based workloads. It also continues the core themes of the EAP 6 major version family of better user experience, improved manageability, and enhanced performance.