August 22, 2013

Complete Configuration of MySQL 5 DataSource in JBoss EAP 6

Introduction

Here I will describe how to configure a MySQL 5 DataSource for JBoss EAP 6.

Install MySQL JDBC Driver as JBoss EAP 6 Module

Create a new directory under modules and a new module.xml file.

Download the MySQL JDBC driver and put it in the same catalog as module.xml. If necessary correct resource path below, with the downloaded jdbc driver file name.

If this is a server installation make sure that the new directories and files get the right permission.

Configure JBoss EAP 6 DataSource

Here we will use JBoss EAP 6 in standalone mode, but if you like to use the domain mode, the configuration is the same. Open $JBOSS_HOME/standalone/configuration/standalone.xml.

Reference

August 21, 2013

Configure UsersRolesLoginModule for JBoss EAP 6

Introduction

In this blog I will show you how to configure a simple JAAS login module, that holds username, passwords and roles in properties file. The login module for this job is org.jboss.security.auth.spi.UsersRolesLoginModule.

Finding the correct source code and documentation for the JBoss EAP 6 login modules, can be a bit tricky and the reason for that, is that the concrete implementation for them are hosted in the sister project Picketbox. For example the exact version that is shipped with JBoss EAP 6.1.0 is 4.0.17.Final-redhat-1. And the jar is located under $JBOSS_HOME/modules/system/layers/base/org/picketbox/main/.

The UsersRolesLoginModule has more to offer than I will show you here, and that is to store the password scrambled and not in clear text. But since the UsersRolesLoginModule is merely for test purpose, I will leave that out here.

Configuration

I will use JBoss EAP 6 in standalone mode, which means that the JBoss configuration file is $JBOSS_HOME/standalone/configuration/standalone.xml. Open it and add the below JAAS security-domain.

Create Users and Assing Roles

Creating users and theirs associated roles are easy since them are located in clear plain text files located under $JBOSS_HOME/standalone/configuration/. Here I will only create one user and one role, but you can create as many as you please.

Configuration

The easiest way to test the security, is to either take an existing war project or create a new zip file add a welcome file (index.html), web.xml and jboss-web.xml. Either way the relevant configuration for the web.xml is below.

And the relevant portion in jboss-web.xml.

August 20, 2013

Configure ActiveMQ 5.8.0 to use MySQL as Persistence Mechanism

Introduction

In this blog I will show you how to change, the default persistence mechanism in Apache ActiveMQ 5.8.0 from KahaDB to instead use a RDBMS. And here I will use MySQL 5, but ActiveMQ supports most of the major vendor of RDBMS.

Install MySQL JDBC Driver

Download driver from maven central repo:
http://search.maven.org/#artifactdetails%7Cmysql%7Cmysql-connector-java%7C5.1.19%7Cjar.

Copy to $ACTIVEMQ_HOME/lib/optional/.

Create ActiveMQ database

Log into mysql and create ActiveMQ database.

Configure MySQL as persistence storage

Open the ActiveMQ configuration, $ACTIVEMQ_HOME/conf/activemq.xml, and add mysql datasource, comment/remove the default KahaDB and finally add the RDBMS persistence adapter.

Test

Now we are ready to test the installation. Restart activemq and check the activemq log for errors, $ACTIVEMQ_HOME/data/activemq.log.

You can also open the activemq web console, to verify that things are working:
URL: http://localhost:8161/admin/
Username: admin
Password: admin

Now lets really test the installation from the activemq web console you can send message. From the web console click Send and choose to send a text message to a new queue.

Afterwards we can check that the message is sent to the queue, by clicking on Queue and our new queue foo.bar. And there see your text message.

You could also verify that the message is really persistent in MySQL by querying your database.

August 18, 2013

Configure Redelivery for ActiveMQ 5.8 Resource Adapter in JBoss EAP 6

In this blog I will show you how to setup ActiveMQ resource adapter in JBoss EAP 6 and then test different redelivery policies.

Before we begin, we need to download the latest Apache ActiveMQ binaries and unzip it. To start, stop and check status we use the activemq script located in the bin folder.

After started the ActiveMQ, we can test the installation by open a web browser and open http://localhost:8161/admin/. The default username is admin and default password is admin.

Now we need to configure JBoss. In this blog we will use JBoss EAP 6.1.0. Download it and unzip it.

The next thing we need to do is to download the Apache ActiveMQ resource adapter. You can find it from maven central repo – http://search.maven.org/remotecontent?filepath=org/apache/activemq/activemq-rar/5.8.0/activemq-rar-5.8.0.rar.

JBoss EAP 6 can be run in two different modes – standalone and domain mode. In this blog we will be using standalone mode, but if you need to run JBoss in domain the below configuration is basically the same.

Now deploy the resource adapter to $JBOSS_HOME/standalone/deployment

Now we are ready to configure JBoss. Open $JBOSS_HOME/standalone/configuration/standalone.xml

The last thing we also need is to configure mdb support for the standalone configuration.

Now we are to test the installation. We do that by creating a simple MDB, that prints out incoming JMS messages and then rollbacks the MDB transaction.

As test client we can send jms message from the ActiveMQ web console

Below follows different test results for different redelivery configuration

InitialRedeliveryDelay=1000
MaximumRedeliveries=5
RedeliveryUseExponentialBackOff=false
RedeliveryBackOffMultiplier=5
                    
18:57:51,140 INFO  [stdout] (default-threads - 2) mdb recieved, redelivered=false
18:57:52,220 INFO  [stdout] (default-threads - 3) mdb recieved, redelivered=true
18:57:53,256 INFO  [stdout] (default-threads - 4) mdb recieved, redelivered=true
18:57:54,296 INFO  [stdout] (default-threads - 5) mdb recieved, redelivered=true
18:57:55,334 INFO  [stdout] (default-threads - 6) mdb recieved, redelivered=true
18:57:56,365 INFO  [stdout] (default-threads - 7) mdb recieved, redelivered=true

-----------------------------------------------------------------------------------------------

InitialRedeliveryDelay=1000
MaximumRedeliveries=5
RedeliveryUseExponentialBackOff=true
RedeliveryBackOffMultiplier=5

19:55:21,453 INFO  [stdout] (default-threads - 2) mdb recieved, redelivered=false
19:55:26,495 INFO  [stdout] (default-threads - 3) mdb recieved, redelivered=true
19:55:51,503 INFO  [stdout] (default-threads - 4) mdb recieved, redelivered=true
19:57:56,510 INFO  [stdout] (default-threads - 5) mdb recieved, redelivered=true
20:08:21,516 INFO  [stdout] (default-threads - 6) mdb recieved, redelivered=true
21:00:26,523 INFO  [stdout] (default-threads - 7) mdb recieved, redelivered=true

delta1 = 5s (calculated value 1*5)
delta2 = 25s (calculated value 5*5)
delta3 = 125s (calculated value 25*5)
delta4 = 625s (calculated value 125*5)
delta5 = 3125s (calculated value 625*5)

-----------------------------------------------------------------------------------------------

InitialRedeliveryDelay=2000
MaximumRedeliveries=5
RedeliveryUseExponentialBackOff=true
RedeliveryBackOffMultiplier=5
                    
22:28:52,542 INFO  [stdout] (default-threads - 2) mdb recieved, redelivered=false
22:29:02,598 INFO  [stdout] (default-threads - 3) mdb recieved, redelivered=true
22:29:52,604 INFO  [stdout] (default-threads - 4) mdb recieved, redelivered=true
22:34:02,609 INFO  [stdout] (default-threads - 5) mdb recieved, redelivered=true

delta1 = 10s (calculated value 2*5)
delta2 = 50s (calculated value 10*5)
delta3 = 250s (calculated value 50*5)
-----------------------------------------------------------------------------------------------    

References