Chapter 15. The Hello World Quickstart
15.1. The Hello World Quickstart Copy linkLink copied to clipboard!
Hello World is a simple quickstart that illustrates how to store and retrieve data from a cache using Red Hat JBoss Data Grid. For this quickstart, users can access the cache in two ways:
- from a servlet.
-
from a
JSFpage using request scoped beans.
All libraries (JAR files) bundles with the application are deployed to JBoss Enterprise Application Platform 7.x. JBoss Data Grid’s Library mode only allows local access to a single node in a distributed cluster. This mode also allows the application to access the data grid functionality within a virtual machine in the target container.
The Hello World quickstart works only in JBoss Data Grid’s Library mode.
Location
JBoss Data Grid’s Hello World quickstart is available at the following location: jboss-datagrid-{VERSION}-quickstarts/
15.2. Quickstart Prerequisites Copy linkLink copied to clipboard!
The prerequisites for this quickstart are as follows:
- Java 8.0 (Java SDK 1.8) or better
- JBoss Enterprise Application Platform 7.x or JBoss Enterprise Web Server 2.x
- Maven 3.0 or better
- Configure the Maven Repository. For details, see Install and Use the Maven Repositories.
15.3. Start Two Application Server Instances Copy linkLink copied to clipboard!
Before deploying the Hello World quickstart, start two instances of your application server (JBoss Enterprise Application Platform 7.x).
Start the First Application Server Instance
Navigate to the Root Directory
In the command line terminal, navigate to the root for your JBoss server directory.
Start the First Application Server
Depending on your operating system, use the appropriate command from the following to start the first instance of your selected application server:
For Linux:
$JBOSS_HOME/bin/standalone.sh
$JBOSS_HOME/bin/standalone.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Windows:
$JBOSS_HOME\bin\standalone.bat
$JBOSS_HOME\bin\standalone.batCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Start the Second Application Server Instance
Clone the Application Server
Create a copy of the selected JBoss Server to create a second instance.
Navigate to the Root Directory
In the command line terminal, navigate to the root for your JBoss server directory.
Start the Second Application Server
Use the appropriate command for your operating system from the following commands. This command starts the server with the provided port offset to ensure that both the server instances run on the same host.
For Linux:
$JBOSS_HOME2/bin/standalone.sh -Djboss.socket.binding.port-offset=100
$JBOSS_HOME2/bin/standalone.sh -Djboss.socket.binding.port-offset=100Copy to Clipboard Copied! Toggle word wrap Toggle overflow For Windows:
$JBOSS_HOME2\bin\standalone.bat -Djboss.socket.binding.port-offset=100
$JBOSS_HOME2\bin\standalone.bat -Djboss.socket.binding.port-offset=100Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.4. Build and Deploy the Hello World Quickstart Copy linkLink copied to clipboard!
Before building and deploying the quickstart, ensure that all the listed prerequisites are met and that the two application server instances are running (see for details).
Build and Deploy the Hello World Quickstart
Navigate to the Required Directory
In the command line terminal, navigate to the root directory of the quickstart on the command line interface.
Build and Deploy to the First Application Server Instance
Use the following command to build and deploy the quickstart to the first application server instance as follows:
mvn clean package wildfly:deploy
# mvn clean package wildfly:deployCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command deploys target/[path]jboss-helloworld-jdg.war to the first running server instance.
Build and Deploy the Second Application Server Instance
Use the following command to build and deploy the quickstart to the second application server instance with the specified ports as follows:
mvn clean package wildfly:deploy -Dwildfly.port=10090
# mvn clean package wildfly:deploy -Dwildfly.port=10090Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command deploys target/[path]jboss-helloworld-jdg.war to the second running server instance.
15.5. Access the Running Application Copy linkLink copied to clipboard!
The Hello World quickstart application runs on the following URLs:
- First Server Instance: http://localhost:8080/jboss-helloworld-jdg
- Second Server Instance: http://localhost:8180/jboss-helloworld-jdg
15.6. Test Replication on the Application Copy linkLink copied to clipboard!
Use the following instructions to test that cache entries are replicating from the first server instance to the second as desired.
Test Replication on the Application
Access the First Server
Access the first application server and enter the key and value.
Access the first application server in a browser window using the following URL:
http://localhost:8080/jboss-helloworld-jdg
http://localhost:8080/jboss-helloworld-jdgCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Insert the key
foo. -
Insert the value
bar.
Access the Second Server
Access the second application server and enter the key and value.
Access the second application server in a browser window using the following URL:
http://localhost:8180/jboss-helloworld-jdg
http://localhost:8180/jboss-helloworld-jdgCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Get Some.
-
Get the key
foo. - Click Put Some More.
-
Insert the key
mykey. -
Insert the value
myvalue.
Get All Keys and Values
Access the first server and request all keys.
Access the first application server in a browser window using the following URL:
http://localhost:8080/jboss-helloworld-jdg
http://localhost:8080/jboss-helloworld-jdgCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Get Some.
- Click Get All to request all key and values.
As the results of the last step show, all the data added at each server has been replicated to the other server.
Entries expire after 60 seconds from the most recent update.
Directly Access Keys in the Cache
To interact with predefined servlets or to directly store and retrieve keys from the cache, use the following URLs:
http://localhost:8080/jboss-helloworld-jdg/TestServletPut
http://localhost:8080/jboss-helloworld-jdg/TestServletPut
http://localhost:8180/jboss-helloworld-jdg/TestServletGet
http://localhost:8180/jboss-helloworld-jdg/TestServletGet
15.7. Remove the Application Copy linkLink copied to clipboard!
Use the following procedure to remove the Hello World application:
Remove the Application
Start the Application Servers
Ensure that both server instances are running.
Navigate to the Root
In the command line terminal, navigate to the root directory of the quickstart.
Remove the Archive
Use the following commands to remove the archive from both the server instances.
Remove the archive from the first server as follows:
mvn wildfly:undeploy
mvn wildfly:undeployCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the archive from the second server as follows:
mvn wildfly:undeploy -Dwildfly.port=10090
mvn wildfly:undeploy -Dwildfly.port=10090Copy to Clipboard Copied! Toggle word wrap Toggle overflow