How to customize a JBoss EAP 6 / WildFly Domain using Properties

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

This article shows how you can customize a JBoss EAP 6 / WildFly running in domain mode using System properties.

It is assumed, when you choose the domain mode configuration that you plan to organize an homogeneous group of servers which are grouped in a Server Group and bound to a specific Profile. Nevertheless it is quite common that each server requires one or more specific settings. For example, you might need to choose a different datasource setting on each server of your domain. Another common requirement is to use a fixed port on every server of your domain.

Let's see how to achieve both examples.

Example 1: We have the following datasource definition in our domain:

<datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true">
	<connection-url>${connection-url}</connection-url>
	<driver>mysql</driver>
	<security>
		<user-name>mysql</user-name>
		<password>mysql</password>
	</security>
</datasource>

The connection URL has been set as a property. Where can we define the value for the System property ? The most specific way, is in the single servers definition (host.xml):

<servers>
	<server name="server-one" group="main-server-group">
		<system-properties>
			 <property name="connection-url" value="jdbc:mysql://localhost:3306/myapp" boot-time="true"/>
		</system-properties>
	</server>
	. . . 
</servers>

Properties can also be specified at host level (host.xml), which means that all servers which are controlled by a Host Controller will share that property:

<host name="master" xmlns="urn:jboss:domain:2.2">

    <system-properties>
        <property name="connection-url" value="jdbc:mysql://localhost:3306/myapp" boot-time="true"/>
    </system-properties>
. . .
</host>

You can also set the System property also at Server Group level (domain.xml), which means that all Server Groups of a Domain will share that property:

 <servers>
        <server name="server-one" group="main-server-group">
            <system-properties>
                 <property name="connection-url" value="jdbc:mysql://localhost:3306/myapp" boot-time="false"/>
            </system-properties>
        </server>
. . .
</servers>	

For the sake of completeness, we will mention that Properties can also be set at domain level (domain.xml). For example:

<domain xmlns="urn:jboss:domain:2.2">

    <extensions>
. . . .
    </extensions>

    <system-properties>
        <property name="connection-url" value="jdbc:mysql://localhost:3306/myapp" boot-time="true"/>
    </system-properties>
   . . . .
</domain>

The purpose of setting boot-time=true is to ensure the value is set at JVM launch (like setting with -D parameter), not waiting for management operations to execute

With all these possible choices, it can happen that a Property is defined at multiple levels. So which one will be actually used by your configuration or applications ? basically the most specific configuration overrides the one which is more generic. So the Server configuration overrides any other configuration, the Host configuration overrides the Server Group and Domain and son on. The following picture depicts the order of precedence when a Property is defined at multiple levels:

jboss wildfly domain system property 

Example 2:

Another common scenario is to provide a specific port on each server of your domain. You can do it automatically using the port-offset attribute however this requires that each single port of your bindings will shift by that offset. Let's say you want to use a port offset of 100 units in your domain but use port 8888 and 8889 for server-one and server-two ? 

In your socket-binding you can simply include a property value as port and set fixed-port to true:

<socket-binding-group name="full-sockets" default-interface="public">  
    <socket-binding name="http" port="${jboss.http.port}" fixed-port="true"/>
     . . .
</socket-binding-group>

Then you can set the System Property at server level as shown in the following example, taken from the host.xml file of the Domain configuration:

<servers>
	<server name="server-one" group="main-server-group">
		<system-properties>
			 <property name="jboss.http.port" value="8888" boot-time="true"/>
		</system-properties>
	</server>
	<server name="server-two" group="main-server-group" auto-start="true">
		<system-properties>
			 <property name="jboss.http.port" value="8889" boot-time="true"/>	
		</system-properties>
                <socket-bindings port-offset="100"/>
	</server>
</servers>

 

Related articles available on mastertheboss.com

JBoss MBeans POJO

JMX MBean services are the core building blocks of the JBoss Appl

How to a dump of JNDI tree with JMX console ?

#2 JBoss Howto. This is the recipe of the day

How to configure JBoss to bind to a different IP ?

  If you want to change the jboss.bind.address property use the 

How to shut down JBoss from remote ?

JBoss recipe of the day

How to create multiple instances of an Mbean?

  Supposing you need two instances of an MBean, let's say one fo

JBoss classloader issues

By default JBoss (prior to version 3.2) uses a flat class loading