############################ # # # WebSphere MQ JMS # # Sample3 # # # ############################ 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 third of three sample applications which uses Pub/Sub to put and get a message. It also uses container managed transactions (TX_REQUIRED) on the putMessage and getMessage methods, and has two additional methods to create and remove a durable subscrip- tion which also have to be marked with TX_REQUIRED for the current implementation. Like Sample1 and Sample2, the instructions that follow are designed to be used with WebSphere MQ and WebSphere Application Server; however, the instructions here are slightly varied because this application uses Pub/Sub and therefore requires the creation of a Topic Connection Factory and a Topic to be available from the JNDI namespace (the other samples require a Queue Connection Factory and a Queue Destination). II. Requirements ---------------- Requires a Queue Manager and requires that the MQ Message Broker be started. In this sample we use the following: Queue Manager = TestBkrQM This name is referenced in the instructions outlined in the following section. Replace this with the appropriate name for your Queue Manager. To start the message broker, issue the following command: strmqbrk -m TestBkrQM Like Sample1 and Sample2, requires the following administered objects to be available from the JNDI namespace: jms/Samples/TCF1 jms/Samples/T1 III. Configure Administered Objects ----------------------------------- Follow the steps outlined below to create a Topic Connection Factory and a Topic Destination in the WebSphere Application Server Administrative Console: ################################################################ # # Create WebSphere MQ Topic 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 Topic Connection # Factories. # 3. Click on the New button and complete the form # with the following values: # # Name = TCF1 # JNDI Name = jms/Samples/TCF1 # Queue Manager = TestBkrQM # Broker Version = Basic # Client ID = TCF1 # # Ensure that the XA Enabled check box is selected. # Accept the default value for all other fields. # # 4. Click OK. # # ------------------------------------- # Create WebSphere MQ Topic 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 Topic # Destinations. # 3. Click on the New button and complete the form # with the following values: # # Name = T1 # JNDI Name = jms/Samples/T1 # Base Topic Name = T1 # # Accept the default value for all other fields. # # 4. Click OK. # ################################################################ IV. Deploy the Bean ------------------- The bean, jmsSample3.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 (Sample3Client.java), along with a script (runClient) to simplify running it. The script will need modification for the location of the WebSphere installation, and the name of the deployed jar file (DeployedjmsSample3.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 topic connection factory defined by 'jms/Samples/TCF1' and publish a message to the topic 'jms/Samples/T1'. The getMessage method will subscribe to the topic connection factory defined by 'jms/Samples/TCF1' and get a message from 'jms/Samples/T1'. 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 pubsub test message" c:\jdk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample3>rem Modify the following to match the local installation c:\jdk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample3>rem Modify the following to match the name of the deployed jar file c:\jdk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample3>c:\Websphere\Appserver\jdk\jre\bin\java -classpath .;c:\Websphere\Appserver\deployedEJBs\DeployedjmsSample3.jar;c:\Websphere\Appserver\jdk\jre\lib\rt.jar;c:\Websphere\Appserver\lib\ejs.jar;c:\Websphere\Appserver\lib\ujc.jar;c:\Websphere\Appserver\lib\iioptools.jar;c:\Websphere\Appserver\lib\servlet.jar; Sample3Client "A pubsub test message" creating durable subscription calling putMessage calling getMessage got message 'A pubsub test message' deleting durable subscription done And here is the resulting output from the application server's stdout: Sample3.ejbCreate() Sample3EJB: createSubscription creating connection setting clientid looking up topic creating durable subscriber closing connection done Sample3.ejbRemove() Sample3.ejbCreate() Sample3EJB: request to put message 'A pubsub test message' creating connection setting clientid Creating session creating topic publisher sending message done Sample3.ejbRemove() Sample3.ejbCreate() Sample3.getMessage() looking up Topic Connection Factory Creating session looking up topic creating subscriber subscribe body is >A pubsub test message< closing subscriber closing connection Sample3.ejbRemove() Sample3.ejbCreate() Sample3EJB destroySubscription Looking up Topic Connection Factory Creating session deleting subscription closing connection done Sample3.ejbRemove()