The Java publish/subscribe sample program is an IBM® MQ MQI clientJava program. The sample runs without modification using a default queue manager listening on port 1414. The task describes this simple case, and indicates in general terms how to provide parameters and modify the sample to suit different IBM MQ configurations. The example is illustrated running on Windows. The file paths will differ on other platforms.
Procedure
Import the Java sample programs
In the workbench, click Window > Open perspective > Other > Java and click OK.
Switch to the Package Explorer view.
Right-click in the white-space in the Package Explorer view. Click New > Java project.
In the Project name field type MQ Java Samples. Click Next.
In the Java Settings panel, switch to the Libraries tab.
Click Add External JARs.
Browse to MQ_INSTALLATION_PATH\java\lib where MQ_INSTALLATION_PATH is the IBM MQ installation folder and select com.ibm.mq.jar and com.ibm.mq.jmqi.jar
Click Open > Finish.
Right-click src in the Package Explorer view.
Select Import... > General > File System > Next > Browse... and browse to the path MQ_INSTALLATION_PATH\tools\wmqjava\samples where MQ_INSTALLATION_PATH is the IBM MQ installation directory.
On the Import panel, Figure 1, click samples (do not select the check box).
Select MQPubSubApiSample.java. The Into folder field should contain MQ Java Samples/src. Click Finish.
Run the publish/subscribe sample program.
There are two ways to run the program, depending on whether you need to change the default parameters.
The first choice runs the program without making any changes:
In the workspace main menu, expand the src folder. Right-click MQPubSubApiSample.javaRun-as > 1. Java Application
The second choice runs the program with parameters or with modified source code for your environment:
Open MQPubSubApiSample.java and study the MQPubSubApiSample constructor.
Modify the attributes of the program.
These attributes are modifiable using the -D JVM switch, or by providing a default value for the System property by editing the source code.
topicObject
queueManagerName
subscriberCount
These attributes are changeable only by editing the source code in the constructor.
hostname
port
channel
To set System properties, code a default value in the accessor, for example:
Or provide the parameter to the JVM using the -D option, as shown in the following steps:
Copy the full name of the System.Property you want to set, for example: com.ibm.mq.pubSubSample.queueManagerName.
In the workspace, right-click Run > Open Run Dialog. Double click Java Application in Create, Manage and Run applications and click the (x) = Arguments tab.
In the VM arguments: pane, type -D and paste the System.property name, com.ibm.mq.pubSubSample.queueManagerName, followed by =QM3. Click Apply > Run.
Add further arguments as a comma separated list, or as additional lines in the pane, without comma separators.
For example: -Dcom.ibm.mq.pubSubSample.queueManagerName=QM3, -Dcom.ibm.mq.pubSubSample.subscriberCount=6.