How do I create JMS temporary destinations programatically?

Solution Unverified - Updated -

Environment

  • Fuse Message Broker 5.5.x
  • Fuse MQ Enterprise 7.x

Issue

How do I create a temporary destination using the Active MQ API?

Resolution

You can create a temporary topic using the createTemporaryTopic() method on your jms session.

The topic will persist for the duration of the topic connection. If you wish to create temporary Queue you would use the createTemporaryQueue() method instead.

Example:

public void testCreateTemporaryTopicThenCreateATopicFromItsName() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic tempTopic = session.createTemporaryTopic();
   String name = tempTopic.getTopicName();
   LOG.info("Created topic named: " + name);
   Topic createdTopic = session.createTopic(name);
   assertEquals("created topic not equal to temporary topic", tempTopic, createdTopic);
}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments