lafual
lafual

Reputation: 775

Deleting Dynamic Topics from Websphere MQ

I have a Java program which is publishing new Topics (Orders) as they are created. When the order is updated the changed Order object is re-published. Sample code below;

Topic topic = topicSes.createTopic("/DepartmentA/ProjectB/Orders/"+ order.getOrderId());
TopicPublisher topicPub = topicSes.createPublisher(topic); 
ObjectMessage om = topicSes.createObjectMessage(order); 
om.setIntProperty(JmsConstants.JMS_IBM_RETAIN, JmsConstants.RETAIN_PUBLICATION); 
topicPub.send(om);

I publish a poison message (Message object with a parameter of 'DEAD') so that existing subscribers know that we are done. However, what I don't understand, is how to dispose of the topic once it is finished, so that new subscribers don't pick it up?

On my MQ Explorer session (MQ Manager 7.5), my Topics list is empty. I assume this is because the topics are dynamic. Only when I right click on [Topics] and choose [Status...] do I see my Topic Strings. If I right click on a Topic String and choose [Clear Local Retained Publication...] the Topic does finally disappear. I say finally, in that it is not immediate, it takes around 30 minutes disappear.

Ideally I would like to dispose of the Topic String programmatically in JMS, or MQ Java libraries or MQ PCF. How do I do this? (I cannot use TemporaryTopics as the publishing process could go down/up during the lifecycle of the Order).

I also tried querying and clearing the Topics via "runmqsc". What I don't understand is;

For DISPLAY TOPIC; what is the syntax to display a Topic String - The syntax states it should be DISPLAY TOPIC (topic) TOPICSTR(string), but for the given string "/DepartmentA/ProjectB/Orders/123", I have tried all sorts of combinations but nothing works for me. I can only seem get it to work for managerd Topics.

For CLEAR TOPICSTR, I can put anything as the Topic String parameter and "runmqsc" never complains, but even if the string is correct, it still does nothing. What should the correct syntax be for CLEAR TOPICSTR?

Should I have made "/DepartmentA" a Managed Topic?

Upvotes: 1

Views: 583

Answers (2)

David Ware
David Ware

Reputation: 301

You're right in realising that the topic strings are dynamic. You might like to read this

https://www.ibm.com/developerworks/community/blogs/messaging/entry/mq_topics_but_which_type?lang=en

or watch this

https://www.youtube.com/watch?v=szqdtIEgTR4

They should explain the concepts you're trying to understand.

As already mentioned, unused topic strings will be garbage collected after 30 minutes by default, this is to save resources. The system needs to be deleting them as quickly as they're being created to ensure the system doesn't become overloaded. But having them there when no-one is publishing to them should not have a functional effect.

You should be aware that there is overhead in constantly generating new topic strings, so if you have many thousands of these being created and deleted you may see that.

For your specific question, use DISPLAY TPSTATUS('string') to see the equivalent of looking at the topic status in MQExplorer (FYI, if you want to wildcard the string you use the topic characters # or +).

CLEAR TOPICSTR simply deletes any retained message currently held for a topic string. A topic string with an associated retained message cannot be garbage collected. If you're not using retained messages it will have no effect.

As you'll see from those links, you only need to make /DepantmentA a managed topic if you want to configure it differently to the rest of the tree, or you want to grant specific access to that branch of the tree.

Upvotes: 2

Umamahesh P
Umamahesh P

Reputation: 1244

The default TREELIFE is 30 mins and you can change the TREELIFE interval. Check the following MQ infocenter URL for details.

http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.pla.doc/q005060_.htm?lang=en

Upvotes: 2

Related Questions