Sample 3

Uses Pub/Sub to put and get a message.

Uses container managed transactions (TX_REQUIRED) on the putMessage
and getMessage methods.

Has two additional methods to create and remove a durable subscription.
These also have to be marked with TX_REQUIRED for the current implementation.

Requires a TopicConnectionFactory and a Topic to be available via JNDI.
The following script can be used to create these object with JMSAdmin:

====== cut here ======

# Example script to insert administered objects for samples into a
# JNDI namespace.
# Ensure that JMSAdmin.config has been correctly configured to access the
# appropriate namespace, and then apply this script using the command
# JMSAdmin < admin.scp

# create the jms subcontext. If the subcontext already exists the def
# command will generate an "unable to create context" error which may
# be safely ignored.
def ctx(jms)
chg ctx(jms)

# create a samples subcontext
def ctx(Samples)
chg ctx(Samples)

# create a WebSphere specific topic connection factory
# This uses all the default settings which map to the default queue manager.
# A non-default queue manager can be specified using the qmgr(name) property.
def wstcf(TCF1)

# create a Topic. 
def t(T1) topic(jms/samples/testTopic)

# display the current context to provide feedback
dis ctx

# exit
end

====== cut here ======

When running this sample it is useful to monitor the stdout of the application
server, since the EJB outputs a number of messages to describe its progress.

Here is the output from the client from a typical run:

runClient.bat "A pubsub test message"

c:\jbk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample3>rem Modify the following to match the local installation

c:\jbk\mqjava\common\jms\com\ibm\mq\jms\wsae\samples\sample3>rem Modify the following to match the name of the deployed jar file

c:\jbk\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()
