I implemented the following to be able to create dynamic queues. I am sure it 
can easily  be adapted for a Topic:

    
  |    /**
  |      * Gets the queue from JNDI. This is synchronized as if the queue does 
not 
  |      * exist, a new queue is created.
  |      * @param iniCtx
  |      * @param destination
  |      * @return
  |      * @throws Exception
  |      */
  |     public synchronized Queue getQueue(InitialContext iniCtx,String 
destination) throws Exception{
  |         Queue queue=null;
  |         try {
  |             queue= (Queue)iniCtx.lookup(destination);
  |         } catch (NameNotFoundException e){
  |             System.out.println("Queue "+destination+" does not exist.");
  |         }
  |         if (queue==null)
  |             queue=createQueue(iniCtx,destination);
  |         return queue;
  |     }
  |    
  |     /**
  |      * Creates a new queue using a JbossMQ (DestinationManagerMBean) only 
method, 
  |      * thus breaking the JMS specifications. 
  |      * @param iniCtx
  |      * @param destination
  |      * @return
  |      * @throws Exception
  |      */
  |     private Queue createQueue(InitialContext iniCtx,String destination) 
throws Exception{
  |         Queue queue=null;
  |         
  |         // Get the MBean server
  |         MBeanServer server = (MBeanServer)
  |         MBeanServerFactory.findMBeanServer(null).iterator().next();
  | 
  |         // Invoke the MBean
  |         server.invoke(
  |           new  ObjectName("jboss.mq:service=DestinationManager"),
  |           "createQueue",
  |           new Object[] { destination, destination },
  |           new String[] { String.class.getName(), String.class.getName()}
  |         );
  |         
  |         queue=(Queue)iniCtx.lookup(destination);
  |         System.out.println("Queue "+destination+" has been created.");
  |         return queue;
  |     }
  |     

With JBossMQ, if you have messages in the queue and your system dies, the next 
time you startup and you create the queue dynamically like this, the messages 
are still there and you will start off from where you left off before you 
system crashed.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3904068#3904068

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3904068


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to