Configure JMS connection factories and destinations

Configure JMS connection queue factory

To configure the JMS connection queue factory, do the following:

  1. Display the default messaging provider:

    Select Resources > JMS Provider > Default messaging.

    Optional: Change the Scope check box to set the level at which the connection factory is to be visible, according to your needs (Server).

  2. In the content pane, under the Connection Factories heading click JMS queue connection factory.

    This displays any existing JMS queue connection factories for the default messaging provider in the content pane.

  3. Click New.

  4. Enter the following and then click OK:

    Administration:

    Name (The name by which the connection factory is known for administrative purposes): IBAConnectionFactory

    JNDI name (The JNDI name that is used to bind the connection factory into the name space): jms/IBAConnectionFactory

    Connection:

    Bus name (The name of the service integration bus that the connection factory is to create connections to. This service integration bus hosts the destinations that the JMS queues and topics represent): Select IBASampleBus.

    JMS queue connection factory

  5. Click Save and then when prompted click Save to Save to Master Configuration.

Configure the destination JMS queue

To configure the destination JMS queue, do the following:

  1. Display the default messaging provider:

    Select Resources > JMS Provider > Default messaging.

    Optional: Change the Scope check box to set the level at which the JMS queue is to be visible, according to your needs.

  2. In the content pane, click JMS queue under Destinations.

    This displays any existing JMS queues for the default messaging provider in the content pane.

  3. Click New.

  4. Enter the following and then click OK:

    Administration:

    Name (the name by which the queue is known for administrative purposes): IBAQueue

    JNDI name (The JNDI name that is used to bind the queue into the name space): jms/IBAQueue

    Connection:

    Bus name: Select IBASampleBus

    Queue name (The name of the queue on a service integration bus that this JMS queue is to use) : Select IBASampleQueue

    JMS queue

  5. Click Save and then when prompted click Save to Save to Master Configuration.

Configuration of a JMS activation specification

The JMS activation specification is based on the Java Connector Architecture (JCA) 1.5 standard, and provides Java connectivity between application servers such as WebSphere Application Server, and enterprise information systems. It provides a standardized way of integrating JMS providers with J2EE application servers, and provides a framework for exchanging data with enterprise systems, where data is transferred in the form of messages.

For earlier versions of WebSphere Application Server, the interface between an MDB and its destination is the listener port. A listener port is a messaging component that can be manually started and stopped by the administrator. When a listener port stopped, the MDB associated with it can no longer process messages. If an MDB fails to process a message several times, the listener port is automatically stopped by the application server. Listener ports are used with the MQ Client Link (the WebSphere Application Server Version 5 provider), and with WebSphere MQ when used as an external JMS provider.

With WebSphere Application Server Version 6, the interface between an MDB and its destination is the JMS activation specification. Because a JMS activation specification is a group of messaging configuration properties not a component, it cannot be manually started and stopped. For this reason, to prevent an MDB from processing messages, you must complete the following tasks:

It is possible to share a single JMS activation specification with multiple MDBs. This simplifies administration because it is only necessary to provide a single set of messaging configuration properties.

To configure a JMS activation specification for the default messaging provider, you use the administrative console to complete the following steps:

  1. Select Resources > JMS Provider > Default messaging.

  2. Click JMS activation specification under Activation Specifications.

  3. Click New.

  4. Enter the following and then click OK:

    - Name (The name by which the activation specification is known for administrative purposes): IBAActivationSpec

    JNDI name (The JNDI name that is used to bind the activation specification into the JNDI name space): jms/IBAActivationSpec

    Destination type (Whether the message-driven bean uses a queue or topic destination): Select Queue

    Destination JNDI name (The JNDI name that the message-driven bean uses to look up the JMS destination in the JNDI name space): jms/IBAQueue

    Bus name (The name of the bus to connect to. Specify the name of the service integration bus to which connections are made. This must be the name of the bus on which the bus destination identified by the Destination JNDI name property is defined. The server to which associated message-driven beans are deployed must be a member of this bus): Select IBASampleBus

    JMS activation specification

  5. Click Save and then when prompted click Save to Save to Master Configuration.

Create and configure sample MDB

Create sample MDB (by.iba.rad257.SampleMDB):

Create MDB

Click Finish.

Copy-paste the following code into onMessage method:

try {
	if (msg instanceof javax.jms.MapMessage) {
		javax.jms.MapMessage inMessage = (javax.jms.MapMessage) msg;
		String name = inMessage.getString("name");
		System.out.println("Sample MDB says : 'Hello, " + name + " !'");				
	} else {
		System.out.println("Sample MDB says: Wrong message type !");
	}
} catch (javax.jms.JMSException e) {
	e.printStackTrace();
	fMessageDrivenCtx.setRollbackOnly();
} catch (Throwable te) {
	te.printStackTrace();
}
					

Bind the Activation Specification and Destination to the MDB

  1. In the Project Explorer View open EJB Deployment Descriptor.

  2. Go to Bean tab.

  3. Select SampleMDB Bean.

  4. On the right side in the Message-Driven Destination section, select:

    Destination type: Queue

  5. On the right side in the WebSphere Binding section, select:

    JCA Adapter: selected

    ActivationSpec JNDI name: jms/IBAActivationSpec

    Destination JNDI name: jms/IBAQueue

    Message-Driven Destination and WebSphere Binding

  6. Save EJB Deployment Descriptor.

Create and configure MDB client

Create new JSP file (index.jsp).

Copy-paste the following JSP code into the page:


<%!
javax.naming.Context ic = null;
javax.jms.QueueConnectionFactory qConnFactory = null;
javax.jms.QueueConnection qConn = null;
javax.jms.Queue queue = null;
javax.jms.QueueSession qSession = null;
javax.jms.QueueSender qSender = null;
javax.jms.MapMessage message = null;

private void greet(String name) {
	try {
		ic = new javax.naming.InitialContext();
		qConnFactory = (javax.jms.QueueConnectionFactory) ic.lookup("java:comp/env/jms/IBACFRef");
		queue = (javax.jms.Queue) ic.lookup("java:comp/env/jms/IBAQRef");
	} catch (Exception e) {
		System.err.println("Sample MDB client : JNDI lookup failed : " + e);
	}

	try {
		qConn = qConnFactory.createQueueConnection();
		qSession = qConn.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
		qSender = qSession.createSender(queue);
		message = qSession.createMapMessage();

		message.setString("name", name);

		qSender.send(message);
		qConn.close();
		System.out.println("Sample MDB client : Message sent !");
	} catch (Exception e) {
		System.err.println("Sample MDB client : Error during message sending : " + e);
	}
}
%>

<%
	greet("World");
%>
					
					

Configure references in the Web Project:

  1. In the Project Explorer View open Web Deployment Descriptor.

  2. Go to References tab.

  3. Click the Add button.

  4. In the Add Reference dialog, select Resource reference and click the Next button.

  5. In the Add Resource Reference dialog select the following:

    Name: jms/IBACFRef

    Type: javax.jms.QueueConnectionFactory

    Authentication: Application

  6. Click the Finish button.

  7. In the WebSphere Binding section define:

    JNDI name: jms/IBAConnectionFactory

    Add Resource Reference

  8. Save Web Projects's Deployment Descriptor (Ctrl + S).

  1. In the Project Explorer View open Web Deployment Descriptor.

  2. Go to References tab.

  3. Click the Add button.

  4. In the Add Reference dialog, select Resource environment reference and click the Next button.

  5. In the Add Resource Environment Reference dialog select the following:

    Name: jms/IBAQRef

    Type: javax.jms.Queue

  6. Click the Finish button.

  7. In the WebSphere Binding section define:

    JNDI name: jms/IBAQueue

    Add Resource Environment Reference

  8. Save Web Projects's Deployment Descriptor (Ctrl + S).

Run index.jsp on server:

[5.4.07 15.07.21:364 EEST] 0000002c EJBContainerI I   WSVR0207I: Preparing to start EJB jar: Chapter4EJB.jar
[5.4.07 15.07.21:380 EEST] 0000002c EJBContainerI I   WSVR0037I: Starting EJB jar: Chapter4EJB.jar
[5.4.07 15.07.21:520 EEST] 0000002c WebGroup      A   SRVE0169I: Loading Web Module: Chaptrer4Web.
[5.4.07 15.07.21:614 EEST] 0000002c VirtualHost   I   SRVE0250I: Web Module Chaptrer4Web has been bound to default_host[*:9080,*:80,*:9443].
[5.4.07 15.07.21:630 EEST] 0000002c ApplicationMg A   WSVR0221I: Application started: Chapter4EAR
[5.4.07 15.07.23:958 EEST] 0000003d ServletWrappe A   SRVE0242I: [/index.jsp]: Initialization successful.
[5.4.07 15.07.24:661 EEST] 0000003d SystemOut     O Sample MDB client : Message sent !
[5.4.07 15.07.24:895 EEST] 0000003f SystemOut     O Sample MDB says : 'Hello, World !'					
					

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide