############################ # # # WebSphere MQ JMS # # Sample1 # # # ############################ CONTENTS: I. Introduction II. Requirements III. Configure Administered Objects IV. Deploy the Bean V. Install the Deployed Bean VI. Run the Bean I. Introduction --------------- This is the first of three sample applications which does a standard put/get from an XA JMS session. The instructions that follow are designed to be used with WebSphere MQ and WebSphere Application Server. II. Requirements ---------------- Requires a Queue Manager, Queue, and Channel. In this sample we use the following: Queue Manager = TESTQM Queue = TESTQ Channel = TESTCHANNEL Queue Manager Port = 3600 These names are referenced in the instructions outlined in the following section. Replace these with the appropriate names for your Queue Manager, Queue, Channel, etc. Also requires the following administered objects to be available from the JNDI namespace: jms/Samples/QCF1 jms/Samples/Q1 III. Configure Administered Objects ----------------------------------- Make the administered objects available from the JNDI namespace by creating a Queue Connection Factory and a Queue Destination in the WebSphere Application Server Administrative Console. Follow the steps outlined below to accomplish this: ################################################################### # # Create WebSphere MQ Queue Connection Factory # # 1. In the Admin' Console, expand Resources and # select WebSphere MQ JMS Provider. # 2. In the pane to the right, under Additional # Properties, select WebSphere MQ Queue Connection # Factories. # 3. Click on the New button and complete the form # with the following values: # # Name = QCF1 # JNDI Name = jms/Samples/QCF1 # Queue Manager = TESTQM # Host = Provide the ip address of the host # machine. # Port = 3600 # Channel = TESTCHANNEL # # Ensure that the XA Enabled check box is selected. # Accept the default value for all other fields. # # 4. Click OK. # # ------------------------------------- # Create WebSphere MQ Queue Destination # # 1. In the Admin' Console, expand Resources and # select WebSphere MQ JMS Provider. # 2. In the pane to the right, under Additional # Properties, select WebSphere MQ Queue # Destinations. # 3. Click on the New button and complete the form # with the following values: # # Name = Q1 # JNDI Name = jms/Samples/Q1 # Base Queue Name = TESTQ # Base Queue Manager = TESTQM # Queue Manager Host = Provide the ip address of the host # machine. # Queue Manager Port = 3600 # Server Connection # Channel Name = TESTCHANNEL # UserID = Provide the UserID used to connect # to the queue manager (i.e. mqm). # # Accept the default value for all other fields. # # 4. Click OK. # # ------------------------------------------------ # Test Connection Between Queue Connection Factory # and Queue Destination # # 1. Log out of the admin console and then stop and restart # the application server. # 2. Once the server has started, expand Resources and select # WebSphere MQ JMS Provider. # 3. In the pane to the right, under Additional Properties, # select WebSphere MQ Queue Destinations. # 4. Select Q1. # 5. Scroll down to the bottom and select MQ Config from the # Additional Properties section. If everything has been # configured properly, the window that appears next will # display information about your queue manager, queue, # channel, listener port, etc.... You should not see any # error messages. If you do, then you will need to debug # and assess your configuration to figure out what is causing # the problem. # ################################################################### IV. Deploy the Bean ------------------- The bean, jmsSample1.jar, must be deployed with the TX_REQUIRED attribute set for the getMessage and putMessage methods. See the WebSphere documentation for details on building and deploying EJBs. V. Install the Deployed Bean ---------------------------- Once the bean has been deployed, you will have an Enterprise Archive file (.EAR). An Enterprise Archive file represents a J2EE application that can be deployed in a WebSphere application server. Follow the steps outlined below to accomplish this: 1. In the Admin' Console, expand Applications and select Install New Application. 2. Browse to the directory where you saved the EAR file. 3. Click Next. 4. Continue to click Next, accepting defaults on all subsequent windows, until you are able to install. 5. Once installed you should receive a message that the application installed successfully. Save the configuration by clicking on the save link and then clicking on the Save button. 6. Log out of the Admin' Console and restart the application server. VI. Run the Bean --------------- A simple client program is provided to invoke the bean (Sample1Client.java), along with a script, runClient, to simplify running it. The script file will need modification for the location of the WebSphere installation, and the name of the deployed jar file (DeployedjmsSample1.jar by default). The client program takes a single parameter which is a string to be put in the test message output from the EJB. The putMessage method will connect to the queue manager defined by 'jms/Samples/QCF1' and put a message to 'jms/Samples/Q1'. The getMessage method will connect to the queue manager defined by 'jms/Samples/QCF1' and get a message from 'jms/Samples/Q1'. While running the bean it is useful to monitor the stdout log from the app' server, as it outputs a number of messages describing its activity. Here is an example output from the client program: $ runClient.bat "A test message" c:\jdk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample1>java -classpath .;c :\Websphere\Appserver\deployedEJBs\DeployedjmsSample1.jar;c:\Websphere\Appserver \jdk\jre\lib\rt.jar;c:\Websphere\Appserver\lib\ejs.jar;c:\Websphere\Appserver\li b\ujc.jar;c:\Websphere\Appserver\lib\iioptools.jar;c:\Websphere\Appserver\lib\se rvlet.jar;c:\Websphere\Appserver\lib\jms.jar Sample1Client "A test message" calling Sample1 EJB with string 'A test message' calling putMessage calling getMessage got message 'A test message' done And here is the corresponding output from the app' server's stdout: Sample1EJB.ejbCreate() request to put message 'A test message' sending message done Sample1EJB.ejbRemove() Sample1EJB.ejbCreate() request to get message 'ID:414d51206361726468752e716d3120200c82c33912600000' getting message body is >A test message< closing receiver closing connection Sample1EJB.ejbRemove()