Monday, August 06, 2007

JMS Implementation with RSA 7.0 and WAS 6.1

Environment:
IBM Rational Software Architect 7.0 with embedded WebSphere Application Server 6.1.

Purpose:
  • Create a JMS client application to send a simple message to a queue defined by WAS 6.1 default messaging provider.
  • Create a MDB to consume the message received by the queue.
Development:
  1. Open RSA, use the New wizard to create an Enterprise Application Project under J2EE group, if you cannot see this selection, check if you are using the J2EE perspective. I called the project minzy.
  2. Click "Show Runtimes" to make sure the v6.1 is selected.
  3. Click "New Modules" to create default modules, check off Web module and Connector module, which we don't need, and change the name of the EJB module to minzyEnt. It's only my preference, you can call it any name.
  4. Rename source folders to "src" in both minzyClient and minzyEnt.
  5. In minzyClient, create a package "tliu.minzy.client" and create a class "MessProducer" with main method.
  6. Delete default package.
  7. Edit MANIFEST.MF under META-INF and change Main-Class to tliu.minzy.client.MessProducer.
  8. From menu Project, select clean and select minzyClient, minzyEnt and minzy, error in minzy and minzyClient will be gone.
  9. In minzyEnt, create package tliu.minzy.ent, use New wizard to create a Enterprise Bean.
  10. Check "Message-driven bean", give name MessConsumer, select package tliu.minzy.ent and check on "Generate an annotated bean class".
  11. Make sure JMS type is javax.jms.MessageListener.
  12. Check off "Add bean to Class Diagram", diagrams are out of the scope.
  13. Now you see all error gone, we are ready to put real codes in.
Code in MessProducer:
    public static void main(String[] args) throws Exception {
InitialContext initCtx = new InitialContext();
javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup("jms/minzyConnectionFactory");
Destination q = (Destination) initCtx.lookup("jms/minzyQueue");
Connection connection = qcf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer queueSender = session.createProducer(q);
TextMessage outMessage = session.createTextMessage();
outMessage.setText("Hello, minzy.");
outMessage.setJMSType("minzy");
outMessage.setJMSDestination(q);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(outMessage);
connection.close();
System.out.println("Minzy mess produced.");
}
Code in MessConsumerBean:
    public void onMessage(javax.jms.Message mess) {
TextMessage text = (TextMessage) mess;
try {
System.out.println("Message Received: " + text.getText());
} catch (JMSException e) {
System.out.println("Oops, exception.");
}
}
Packaging:
Export minzyClient to C:\development\applications\minzyClient.ear.
Export minzyEnt to C:\development\applications\minzyEnt.ear.

Deployment:
  1. In Servers view in RSA, select WebSphere Application Server v6.1 and start the server.
  2. After started, right click the server and select "Run administrative console".
  3. Navigate Service integration > Buses > New and create a bus "minzyBus".
  4. Navigate minzyBus > Bus members > Add and add server "cledt-123691Node02:server1".
  5. Open a command window, and change directory to "C:\Program Files\IBM\SDP70\runtimes\base_v61\bin", run "setupCmdLine.bat".
  6. Run "wsadmin -f installSdoRepository.jacl -createDb cledt-123691Node02 server1".
  7. Verify SDO Repository successfully started under Enterprise Applications. Note, install once per server.
  8. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL_RA -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -nodeName cledt-123691Node02". Note, install once per node.
  9. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -serverName server1 -nodeName cledt-123691Node02".
  10. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL_HTTP -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -serverName server1 -nodeName cledt-123691Node02".
  11. In the admin console, navigate to Servers > Application Servers > server1 > Endpoint Listeners and select New. Specify SOAPHTTPChannel1 as name, http://cledt-123691.agna.amgreetings.com:9081/SOAPHTTPChannel1 as URL root, http://cledt-123691.agna.amgreetings.com:9081/sibws as WSDL root.
  12. Select the "Connection Properties" of SOAPHTTPChannel1, client New and select minzyBus.
  13. Go to minzyBus > Destinations, there should be a new destination called cledt-123691Node02.server1.SOAPHTTPChannel1Reply.
  14. Navigate minzyBus > Destinations > New and create a Queue type destination "minzyDestination".
  15. Navigate Resources > JMS Providers > Default messaging. Select Node as the scope.
  16. Select Connection factories and click New. Enter minzyConnectionFactory as name, jms/minzyConnectionFactory as JNDI name, select minzyBus, enter localhost:7277 in the "Provider endpoints" box, leave other default and click OK.
  17. Go back to Default messaging provider and select Queues. Click New.
  18. Enter minzyQueue as name, jms/minzyQueue as JNDI name, select minzyBus and minzyDestination. Click OK.
  19. Go back to Default messaging provider and select Activation specifications. Click New.
  20. Enter minzyActivation as name, eis/minzyActivation as JNDI name, jms/minzyQueue as Destination JNDI name and select minzyBus. Click OK and save all your changes.
  21. Install minzyEnt.ear in admin console. Make sure Deploy enterprise beans are checked. Enter eis/minzyActivation as Activation Specification Target and jms/minzyQueue as Destination.
  22. Restart server.
Run:

In a command line window, change directory to C:\Program Files\IBM\SDP70\runtimes\base_v61\bin. Run,

setupCmdLine.bat
launchClient \development\applications\minzyClient.ear -CCBootstrapPort=2810

In the command line window, you shall see,
WSCL0014I: Invoking the Application Client class tliu.minzy.client.MessProducer
Minzy mess produced.

In the server console, you shall see,
[8/6/07 13:33:32:455 EDT] 0000002f SystemOut O Message Received: Hello, minzy.

The End.

2 comments:

Tom :L said...

To drug and drop application minzy in workbench to WAS 6.1 under Servers view and get deployed, open the Deployment Descriptor of minzyEnt, go to tab Bean, select MessConsumer, then go the WebSphere Bindings section, select JCA Adapter, enter eis/minzyActivation for ActivationSpec JNDI name, jms/minzyQueue for Destination JNDI name, save and redeploy.

Anonymous said...

Good Morning!!! j2eeinaction.blogspot.com is one of the most outstanding innovative websites of its kind. I enjoy reading it every day. I will be back.