Monday, September 1, 2014

Amazon Web Services (AWS) FREE Hello World!

In the following steps, we will setup a simple AWS architecture assuming that you already completed your AWS account registration. We will be using the FREE AWS instances, so you do not have to worry about the billing ;)

1. Login the AWS Dashboard Console:

https://console.aws.amazon.com/console/home

2. Go to EC2:


3. Go to Instances > Launch Instance.

4. Make sure to check the "Free tier only" from the left side.

5. Select the OS that like from the list, in my case I will select Amazon Linux AMI 2014.09.1 (HVM).

6. Select the instance type of General Purpose, t2.micro which is FREE.

7. In the next configuration step, make sure to set Auto-assign Public IP to Enabled.



8. Add storage.


9. Configure the security.










10. Now you are ready to launch your first AWS instance.




11. Select to create new key pair to download it to your local PC.





12. After launching your instance, you should be able to see its status.






13. Check the Public IP and DNS in the instance properties:






14. To access the instance using SSH:

a. Open an SSH client PuTTY on Windows
b. Locate your private key file (aws-demo.pem). 
c. Restrict access to the key
    chmod 400 aws-demo.pem
d. Connect to your instance using its Public IP or DNS:
    ssh -i aws-demo.pem ec2-user@54.68.96.206


Congratulations!! :)

Tuesday, May 13, 2014

Installing JBoss EAP 6.2 on RedHat Linux

In this tutorial, I will be installing JBoss EAP 6.2 that will be using Oracle JDK 1.6 Update 45 on Red Hat Linux.

1.   Download Oracle jdk-6u45-linux-x64.bin
2.   Download JBoss EAP 6.2 (jboss-eap-6.2.0.zip) from JBoss download page.
3.   Create jboss user which will install and manage JBoss using:

     # adduser jboss 
     # su - jboss

4.   Copy the downloaded JDK and JBoss to the jboss home /home/jboss
5.   Install the JDK this extract the JBoss using:

      [jboss@lab04 ~]$ ./jdk-6u45-linux-x64.bin
      [jboss@lab04 ~]$ unzip jboss-eap-6.2.0.zip

6.   To setup JBoss as OS service and make it start automatically, use:

      [root@lab04 ~]# mkdir /etc/jboss-as
      [root@lab04 ~]# cp /home/jboss/jboss-eap-6.2/bin/init.d/jboss-as.conf /etc/jboss-as/.
      [root@lab04 ~]# cp /home/jboss/jboss-eap-6.2/bin/init.d/jboss-as-domain.sh /etc/init.d/.
      [root@lab04 ~]# cd /etc/init.d/
      [root@lab04 init.d]# chkconfig --add jboss-as-domain.sh
      [root@lab04 init.d]# chkconfig jboss-as-domain.sh on

7.   Edit the following parameters in /etc/jboss-as/jboss-as.conf

      JBOSS_USER=jboss
      JBOSS_HOME=/home/jboss/jboss-eap-6.2
      JAVA_HOME=/home/jboss/jdk1.6.0_45 

8. Now, you can start the domain using:

      [root@lab04 init.d]# service jboss-as-domain.sh start

Monday, May 12, 2014

How to add PostgreSQL JDBC driver to JBoss as core module?

1.   Check the support version of the PostgreSQL JDBC driver that is supported with JBoss version that you are using in "JBoss Enterprise Application Platform (EAP) 6 Supported Configurations"

For example, JBoss 6.2 is supported with PostgreSQL 9.2 JDBC4 Postgresql Driver.

2.   Download the PostgreSQL JDBC Driver from PostgreSQL JDBC Drivers download page.

3.  Place the download jar file postgresql-9.2-1004.jdbc4.jar under

     $EAP_HOME/modules/org/postgresql/main/

4.   Create XML file $EAP_HOME/modules/org/postgresql/main/module.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
   <resources>
     <resource-root path="postgresql-9.2-1004.jdbc4.jar"/>
   </resources>
   <dependencies>
     <module name="javax.api"/>
     <module name="javax.transaction.api"/>
   </dependencies>
</module>

5.   Restart JBoss domain/standalone servers to get the new module loaded using:

     # service jboss-as-domain.sh restart

6. Start the jboss-cli in connected mode:

     $EAP_HOME/bin/jboss-cli.sh --connect

7.   Execute the below command in CLI:

     /profile=full/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)

NOTE:
Use the above bold values in all steps because this caused some pain while configuring this by myself :) any inconsistency in names, paths, parameters will cause this error:


JBAS010441: Failed to load module for driver [org.postgres]





Friday, October 4, 2013

RabbitMQ Upgrade


Problem







I am currently running vFabric RabbitMQ 2.8.6 that was installed using the generic installer  vfabric-rabbitmq-server-2.8.6.tar.gz in a customized directory /apps/appuser/springsource/vfabric-rabbitmq-server-2.8.6/

Now, it is required to upgrade it to vFabric RabbitMQ 3.0.4.

** Although I am using vFabric RabbitMQ, but the same is applicable on the native RabbitMQ

Analysis

The default RPM installer will use the standard path /var/lib/rabbitmq/mnesia/ to store mnesia database that contains the queues and exchanges definitions, also the persistent messages are located under the same directory /var/lib/rabbitmq/mnesia/rabbit\@<hostname>/

The generic installer vfabric-rabbitmq-server-2.8.6.tar.gz stored mnesia database and persistent messages under a customized directory path  /apps/appuser/springsource/vfabric-rabbitmq-server-2.8.6/var/lib/rabbitmq/mnesia.

As described in the RabbitMQ 3.0.4 Release Notes, to upgrade a non-clustered RabbitMQ 2.8.6 to 3.0.4, simply install the new version 3.0.4 and all configuration and persistent message data is retained but as per our standards the new 3.0.4 installation will be at  /apps/appuser/springsource/vfabric-rabbitmq-server-3.0.4/ and it will not detect the old mnesia directory which mean none of the configuration or messages will be migrated to 3.0.4 installation.

Workaround

As a workaround, you can overcome this limitation by:


  1. Check the queues and messages from the RabbitMQ 2.8.6 console http://<hostname:55672>
  2. Shutdown RabbitMQ 2.8.6
  3. Backup the installation directory (/apps/appuser/springsource/vfabric-rabbitmq-server-2.8.6/)
  4. Install the RabbitMQ 3.0.4 to the new customized directory /apps/appuser/springsource/vfabric-rabbitmq-server-3.0.4/
  5. Make sure that RabbitMQ is not running
  6. Copy all files under the old mnesia directory from /apps/appuser/springsource/vfabric-rabbitmq-server-2.8.6/var/lib/rabbitmq/mnesia/rabbit@<hostname> to /apps/appuser/springsource/vfabric-rabbitmq-server-3.0.4/var/lib/rabbitmq/mnesia/rabbit@<hostname>
  7. Start RabbitMQ 3.0.4
  8. Check if the queues, exchanges and messages from the RabbitMQ 3.0.4 console http://<hostname:15672>
  9. Your queues, exchanges, and messages will be there :)

Limitaions

This workaround is only valid on the same host server, moving mnesia database is not supported between different hosts with different hostnames.

Tuesday, September 24, 2013

RabbitMQ Worker Example

After RabbitMQ installation, tried simple programs to send and receive messages from a named queue.

In this example, we'll create a Work Queue that will be used to distribute time-consuming tasks among multiple workers to avoid doing a resource-intensive task immediately and having to wait for it to complete by scheduling the task to be done later.



We encapsulate a task as a message and send it to a queue. A worker process running in the background will pop the tasks and eventually execute the job. When you run many workers the tasks will be shared between them.


  1. Download the Java client from download page
  2. Extract the downloaded rabbitmq-java-client-bin-3.1.5.zip 
  3. Copy all *.jar files from the extracted folder to C:\RabbitMQ
  4. Copy NewTask.java from this link (open this link and copy the code from there to C:\RabbitMQ\NewTask.java)
  5. Copy the Worker.java from this link (open this link and copy the code from there to C:\RabbitMQ\Worker.java)
  6. Make sure that JAVA_HOME/bin is part of PATH
  7. Run the following commands to compile NewTask.java and Worker.java

cd C:\RabbitMQ
javac -cp rabbitmq-client.jar NewTask.java Worker.java


     8. You need two consoles to run the Workers that represents the two consumers, run the following command in both consoles to start the workers:

java -cp .;commons-io-1.2.jar;commons-cli-1.1.jar;rabbitmq-client.jar Worker

     9. Run the following command to start publishing new tasks

java -cp .;commons-io-1.2.jar;commons-cli-1.1.jar;rabbitmq-client.jar NewTask



More technical details are available here.


Monday, September 23, 2013

RabbitMQ Installation

In this tutorial, we will go through the RabbitMQ installation and testing steps on local Windows 7 64-bit machine.
The steps are based on RabbitMQ 3.1.5 that was the latest release at the time of writing this tutorial.

Erlang Installation


As per described on Erlang Versions page, you will need Erlang R15B or later to run RabbitMQ on a 64bit Windows machine.


  1. Download R15B02 Windows 64 Bit Binary File from Erlang R15B02 download page.
  2. Double click the executable otp_win64_R15B02_with_MSVCR100_installer_fix.exe
  3. Follow the wizard steps (click the screen shots to see further details).



RabbitMQ Installation


  1. Download the latest available release of RabbitMQ 3.1.5 from download page
  2. Double click the executable rabbitmq-server-3.1.5.exe
  3. Follow the wizard steps (click the screen shots to see further details).


After the installation is completed, you will have RabbitMQ running on default port 5672
You can control RabbitMQ using the shortcuts in start menu:


Java Clients

RabbitMQ is a message broker. The principal idea is pretty simple: it accepts and forwards messages that are binary blobs of data.

In this part of the tutorial (details on how this works is available here) we'll write two programs in Java; a producer that sends a single message, and a consumer that receives messages and prints them out. It's a "Hello World" of messaging.
  1. Download the Java client from download page
  2. Extract the downloaded rabbitmq-java-client-bin-3.1.5.zip 
  3. Copy all *.jar files from the extracted folder to C:\RabbitMQ
  4. Copy the Send.java from this link (open this link and copy the code from there to C:\RabbitMQ\Send.java)
  5. Copy the Recv.java from this link (open this link and copy the code from there to C:\RabbitMQ\Recv.java)
  6. Make sure that JAVA_HOME/bin is part of PATH
  7. Run the following command to compile Send.java and Recv.java
cd C:\RabbitMQ
javac -cp rabbitmq-client.jar Send.java Recv.java

     8. Run the following command to start the consumer:

java -cp .;commons-io-1.2.jar;commons-cli-1.1.jar;rabbitmq-client.jar Recv
    
     9. Run the following command to start the producer:

java -cp .;commons-io-1.2.jar;commons-cli-1.1.jar;rabbitmq-client.jar Send



Saturday, September 14, 2013

RabbitMQ


RabbitMQ



RabbitMQ is a message broker. In essence, it accepts messages from producers, and delivers them to consumers. In-between, it can route, buffer, and persist the messages according to rules you give it.

The RabbitMQ server is an implementation of an Advanced Message Queuing Protocol (AMQP) broker. It is written on the widely-used Erlang/Open Telecom Platform (OTP), an "always available‟ platform that has been in production use in carrier grade telcos since the late 1990s. The core server is unusually compact, with only 12,000 lines of code. Because RabbitMQ implements the open AMQP protocol, it is not necessary to know Erlang, and many users prefer to manage the broker using Java or Ruby.

RabbitMQ, and messaging in general, uses these terms:


  • Producing: means nothing more than sending
  • Producer "P": A program that sends messages
  • Queue: is the mailbox that lives inside RabbitMQ. The messages that flow through RabbitMQ and your applications can be stored only inside a queue. A queue is an infinite buffer where you can store as many messages as you like

Many producers can send messages that go to one queue - many consumers can try to receive data from one queue.

  • Consuming: is receiving messages
  • Consumer "C": is a program that mostly waits to receive messages

Producer, consumer, and broker do not have to reside on the same machine; indeed in most applications they don't.