I use WMQ 7.5 on Windows 2012 Server(A). Created a Topic named "Prices", subscriptions with different topic strings("Prices/Fruit/Apples", "Prices/#/#" and "Prices/Vegetable/Potatoes") to match the topic tree and created queues for these subscriptions.
Using WMQ Explorer on server A, I can test and verify that my topic, subscriptions and queues are working properly. In order to do the test, I run Test Publication option and provide a Topic String and a message.
For example, if I use Topic String "Prices/Fruit/Apples" the published message is delivered to "Prices/Fruit/Apples" and "Prices/#/#" subscription's queues as expected.
The question is how to set the topic string programatically in a publisher that uses JMS.
My publisher resides on another Windows 2012 Server(B). This is a standalone Java SE application and using the JMS Interfaces. The WMQClient is installed on this server. I have created administered TopicConnectionFactory and Topic objects using the JMSAdmin utility. I set the name of Topic admin object to "Prices".
First of all, there is no method in JMS that would set a Topic String. IBM doc indicates that Topic String is an IBM feature and not covered in JMS. I was expecting that I would be able to set a JMSProperty on the Message object to present the topic string to the server in the header section of the message. Regular WMQ Classes can do that but JMS cannot.
Secondly, there are two workarounds both of which are not acceptable to me.
Workaround 1) Create administered JNDI Topic Objects named exactly as the topic string of the subscription. If I have 15 subscriptions I have to create 15 JNDI Topic objects and choose the correct JNDI object for the appropriate subscription.
Workaround 2) Do not use JNDI when creating the JMS Topic object. Instead, use the IBM's MQTopic object by instantiating the MQTopic with the Topic String as its name. This solution ties my publisher code directly to IBM classes and makes my solution less portable.
As I said, I believe that the Message object header should carry the Topic String information to the server. That would be an acceptable solution.
Below is some code that may clarify what I am doing in the publisher.
TopicConnectionFactory tcf = (TopicConnectionFactory)context.lookup("TCF"); //Below Topic t is coming from JNDI which is a MQTopic with Name "Prices" Topic t = (Topic)context.lookup("TPrices"); //Below Topic tFruitPrices is coming //from JNDI which is a MQTopic with Name "Prices/Fruit/Apples" Topic tFruitPrices = (Topic)context.lookup("TFruitPrices"); //Below Topic tIBM uses IBM classes directly to create a Topic object Topic tIBM = new MQTopic("Prices/Vegetable/Potatoes"); TopicConnection tc = tcf.createTopicConnection(); TopicSession s = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); //Below I can choose different topics such as t, tFruitPrices or tIBM to //have the message delivered to different subscriptions TopicPublisher tp = s.createPublisher(tIBM); Message m = s.createTextMessage("From the MyEclipsePublisher"); tp.publish(m); tp.close(); s.close(); tc.close();
Does anyone know if there is an acceptable workaround on this issue?
Thanks, -Dogan Atay