Lab - Message Driven Beans

Preview:

Citation preview

Creating Message Driven Beans

Alvin Reyes

Agenda

• Install Pre-requisite Softwares and DB Connection

• Develop a simple Message Driven Bean.

Pre-requisites

• Eclipse IDE (Bundled with JBoss 6)• Jboss Server (

http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.Final/)

Eclipse IDE

http://www.eclipse.org/

http://www.jboss.org/tools/download/

Eclipse IDE Download

Jboss Eclipse Plugin

JBoss Server

• Download the Application Server:http://sourceforge.net/projects/jboss/files/JBos/JBoss-6.0.0.Final/

Default Username: adminDefault Password: admin

JBoss Server Installation

Install Jboss Server on your Eclipse IDE.Step 1: Go to New > Server > ServerStep 2: Choose Jboss AS 6.0Step 3: Define the Location of the Jboss AS

JBoss Server

Define the Home directoryof JBoss AS and click Finish.

Project Overview

For this session: We’ll create a Simple Message Driven Bean.

Create Topic• Open the Jboss Administrator Console (http://localhost:8080/admin-console

)• Create new Topic with JNDI name: jms/sampletopic

Create TopicCreate new Topic with JNDI name: jms/sampletopic

Name: sampletopic / JNDI Name: jms/sampletopic

Create TopicAdd Roles to the Topic:

Click OK > return to Topic Configuration > Click Save.

Create TopicSuccessfully Created the Topic:

Make sure that the Status is UP. This ensure us that the Topic is ready to serve message request from clients.

Create Enterprise Java Bean Project

Note: You can skip the Project creation if you already have an existing EJBproject.

1. Go to > New > EJB > EJB Project2. Name: ejbsampleproject_<name>3. Target: JBoss 6.4. Create EAR Project5. Create Client Project6. Click Next to Finish

We will now create the EJB that will serve as the consumer of the requests

EJB Project – Message Driven Bean

Generated:– EJB Project– Client Project– EAR

EJB Project – Message Driven BeanMake sure that:

– Jboss Library is included on the Build Path of EJB and Client.

Create new Message Driven BeanJava Package: com.gradu.ejb.samplebeansClass name: SampleMessageDrivenBeanTopic

EJB Project: Develop the Bean

Create new Message Driven Bean

Click Finish

EJB Project: Develop the Bean

Create new Message Driven BeanThe Wizard Generated the following:

1. Session Bean named “SampleMessageDrivenBeanTopic”

EJB Project: Develop the Bean

Create new Message Driven BeanGenerated Session Bean:

EJB Project: Develop the Bean

Create new Message Driven BeanAdd a Activation Configuration to include our Queue

EJB Project: Develop the Bean

Create a new Client Class

Create a new class on the client project. This client will be the one calling our Message Driven Bean from the Application Server.

EJB Project: Develop the Client

Java Package: com.gradu.ejb.clientClass name: SampleTopicProducerClient

Modify the Client Class to Call our BeanCreate a new class on the client project. This client will be the one calling our Session Bean from the Application Server.

EJB Project: Develop the Client

Deploy the Session Bean

We need to deploy the session bean first before executing the Sample Client.

EJB Project: Develop the Client

Run the EAR file on the server to deploy the EJB Components.

Verify Deployment from Console

After running the EAR file (deployment), we need to verify if the Application ServerIndeed deployed our beans.

EJB Project: Develop the Client

If the above lines are shown on the Console, then the Session Bean was successfully deployed.

Test the Session Bean using the Client ClassRun the Client Class.

EJB Project: Testing the Bean

If you were able to see the value thrown from the Session Bean, that means you have successfully called the Bean from the Application Server.

Check Topic MetricsRun the Client Class.

EJB Project: Testing the Bean

If you were able to see the value thrown from the Session Bean, that means you have successfully called the Bean from the Application Server.

Recommended