The Novell exteNd Messaging Platform's JMS supports API's for programatically ceating and destroying destinations (queue or topics). Also, these API's let you set the destination properties shown in Table 1 of the Destination Administration section.
There are two sample programs for this section:
This example provides two utility functions for creating a queue and a
topic. There is also a main
method for creating queue and
topics from the command line. The source code for the Create
class is
shown below:
package destAdmin; import javax.jms.Queue; import javax.jms.Topic; import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; import javax.naming.InitialContext; import com.sssw.jms.api.JMQDestination; import com.sssw.jms.api.JMQQueueConnection; import com.sssw.jms.api.JMQTopicConnection; import com.sssw.jms.api.admin.JMQDestinationAdmin; // Note: destination creation requires private APIs public class Create { public static void main(String[] args) throws Exception { | if (args.length == 2) { | | if (args[0].equals("-topic")) { | | | Topic t = createTopic(args[1]); | | | System.out.println("created topic " + t); | | | System.exit(0); | | } else if (args[0].equals("-queue")) { | | | Queue q = createQueue(args[1]); | | | System.out.println("created queue " + q); | | | System.exit(0); | | } | } | | System.out.println("Usage: Create -command name"); | System.out.println(" where command is queue or topic"); | | System.exit(0); } public static Topic createTopic(String topicName) throws Exception { | // get the initial context | InitialContext ctx = new InitialContext(); | | // create a JMQ topic connection | TopicConnectionFactory tconFactory = (TopicConnectionFactory) ctx. | lookup("topic/connectionFactory"); | JMQTopicConnection topicConn = (JMQTopicConnection) tconFactory. | createTopicConnection(); | | // create a topic | JMQDestinationAdmin destAdmin = topicConn.getDestinationAdmin(); | Topic topic = (Topic) destAdmin.createDestination(topicName, | JMQDestination.TOPIC, null); | | // close the topic connection | topicConn.close(); | | return topic; } public static Queue createQueue(String queueName) throws Exception { | // get the initial context | InitialContext ctx = new InitialContext(); | | // create a JMQ queue connection | QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx. | lookup("queue/connectionFactory"); | JMQQueueConnection queueConn = (JMQQueueConnection) qconFactory. | createQueueConnection(); | | // create a queue | JMQDestinationAdmin destAdmin = queueConn.getDestinationAdmin(); | Queue queue = (Queue) destAdmin.createDestination(queueName, | JMQDestination.QUEUE, null); | | // close the queue connection | queueConn.close(); | | return queue; } }
The connections created by a JMS connection factory can be cast
to either
JMQTopicConnection
or
JMQQueueConnection.
This class has a getDestinationAdmin
method which returns a
JMQDestinationAdmin object.
The JMQDestinationAdmin
has several methods for managing destinations. In the
above example, we use the createDestination
method to create
destinations. This method takes three parameters:
The destination name.
The destination type (QUEUE or TOPIC).
The destination properties. This may be null if the destination should have the default properties.
Destroying destination is also performed using the JMQDestinationAdmin
class. Below is an example, which has two utility method for deleting a
queue and a topic. They both use the deleteDestination
method which take a name and a destination type as arguments.
package destAdmin; import javax.jms.Queue; import javax.jms.Topic; import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; import javax.naming.InitialContext; import com.sssw.jms.api.JMQDestination; import com.sssw.jms.api.JMQQueueConnection; import com.sssw.jms.api.JMQTopicConnection; import com.sssw.jms.api.admin.JMQDestinationAdmin; // Note: destination destruction requires private APIs public class Destroy { public static void main(String[] args) throws Exception { | if (args.length == 2) { | | if (args[0].equals("-topic")) { | | | deleteTopic(args[1]); | | | System.out.println("deleted topic " + args[1]); | | | System.exit(0); | | } else if (args[0].equals("-queue")) { | | | deleteQueue(args[1]); | | | System.out.println("deleted queue " + args[1]); | | | System.exit(0); | | } | } | | System.out.println("Usage: Destroy -command name"); | System.out.println(" where command is queue or topic"); | | System.exit(0); } public static void deleteTopic(String topicName) throws Exception { | // get the initial context | InitialContext ctx = new InitialContext(); | | // create a JMQ topic connection | TopicConnectionFactory tconFactory = (TopicConnectionFactory) ctx. | lookup("topic/connectionFactory"); | JMQTopicConnection topicConn = (JMQTopicConnection) tconFactory. | createTopicConnection(); | | // create a topic | JMQDestinationAdmin destAdmin = topicConn.getDestinationAdmin(); | destAdmin.deleteDestination(topicName, JMQDestination.TOPIC); | | // close the topic connection | topicConn.close(); } public static void deleteQueue(String queueName) throws Exception { | // get the initial context | InitialContext ctx = new InitialContext(); | | // create a JMQ queue connection | QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx. | lookup("queue/connectionFactory"); | JMQQueueConnection queueConn = (JMQQueueConnection) qconFactory. | createQueueConnection(); | | // create a queue | JMQDestinationAdmin destAdmin = queueConn.getDestinationAdmin(); | destAdmin.deleteDestination(queueName, JMQDestination.QUEUE); | | // close the queue connection | queueConn.close(); } }
As mentioned previously, you will need administrative rights in order to manage destinations when a JMS server has security enabled. To connect to the JMS server as administrator, you need to use create a connection with an administrator's username and password.
Copyright © 2003, 2004 Novell, Inc. All rights reserved. Copyright © 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.