13 Replies Latest reply: Nov 20, 2008 8:42 AM by Poonam Agarwal RSS

Programmaticaly create queue

Pascal Lambert Newbie

Hi,

We are currently using Fiorano as our JMS server and we would like migrate to JBoss Messaging.
But to do so, we also need to be able to create Queue on the fly. One of the feature of our software is to give users the ability to subscribe to some data changes and receive them in a personal queue. So we need to create a queue for each subscription and also be able to create user (I know this is not part of JMS spec and we are ok to use vendor specific api). I've look at the source code but I don't see how to persist, through some api, a Queue definition in the "server/jms/jbossmq-destinations-service.xml" file.
Is it possible to do so?

  • 1. Re: Programmaticaly create queue
    Richard Porter Newbie

    One solution you might consider is creating a single queue to handle all the traffic of this dynamic type, then using metadata to distinguish one recipient from another. In this way, you configure a single real queue on the server, but have an infinite number of virtual queues.

    For extremely high load, this is suboptimal, but for moderate volume should perform with roughly the same characteristics as a dynamic queue solution.

  • 2. Re: Programmaticaly create queue
    Ovidiu Feodorov Master

    You can create a queue programmatically by invoking the "createQueue" JMX method on the ServerPeer MBean. Upon the method completion, your new queue will be accessible in JNDI and also through the JMX interface, similarly to any regular ("deployed") queue.

    The queue is handled like any other regular queue, so if the server crashes, the queue's state can be recovered from the database, but your program will have to somehow remember that it created the queue dynamically, and re-create it programmatically after recovery. The messaging server doesn't handle this for you. It is, however, something relatively simply to implement at application level.

    To see an example of how this works, take a look at DestinationManagerTest.testCreateQueueProgramatically()

  • 3. Re: Programmaticaly create queue
    VAkuthota Newbie

    Do i need to migrate to JBoss Messaging from JBoss MQ to create the queues programatically ??

  • 4. Re: Programmaticaly create queue
    Ovidiu Feodorov Master

    JBossMQ can also create queues programatically.

  • 5. Re: Programmaticaly create queue
    Dan Liu Apprentice

    Why do I get InstanceNotFoundException ? here is my code:

    mbeanServer = MBeanServerFactory.createMBeanServer();
    ObjectName objName = new ObjectName("jboss.messaging:service=ServerPeer");
    mbeanServer.invoke(objName, "createQueue",
     new Object[] { "anyname", null },
     new String[] { "java.lang.String", "java.lang.String"} );
    


  • 6. Re: Programmaticaly create queue
    Ovidiu Feodorov Master

    I don't know.

    Do your run that code from within the server VM?

    Did you start the Messaging server?

    Do you see the MBean in the jmx console?

  • 7. Re: Programmaticaly create queue
    Doug Schnelzer Newbie

    So what is the best way to receive messages in the server if a queue is created programmatically? An MDB destination is set at deployment. Should I start a Runnable consumer on the server?

  • 8. Re: Programmaticaly create queue
    praveen Newbie

    I also have the same requirement in creating the Queues programatically instead of maintaining the JBoss deploy folder.

    I maintain my queue name in one of my configuration table, while starting up the server reads these queue names and deploys using following code.


    MBeanServerConnection mBeanServer = lookupMBeanServerProxy();
    ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
    String queueName = jndiName.substring(jndiName.lastIndexOf('/') + 1);
    mBeanServer.invoke(serverObjectName, "deployQueue", new Object[] {
    queueName, jndiName }, new String[] { "java.lang.String","java.lang.String" });


    REMEMBER, 1.2 HAS A SMALL BUG OVER 1.1. IT IS NO LONGER A "createQueue", IT IS "deployQueue".

    -APK

  • 9. Re: Programmaticaly create queue
    THANG LE Newbie

    I have some questions relating this topic:
    1. How many Queues can we safely create dynamically under JBoss 4.0.3? Is it a recommended way?
    2. What is default persistence of Queues created in this way? Can we set persistent method for these Queues?
    3. What API can we use to remove Queues dynamically? Does it clean up all related data of this Queue in database (presume that we can set JDBC persistent model for dynamic created Queues)?

    Thanks a lot in advance

  • 10. Re: Programmaticaly create queue
    Tim Fox Master

     

    "thangle" wrote:
    I have some questions relating this topic:
    1. How many Queues can we safely create dynamically under JBoss 4.0.3? Is it a recommended way?


    JBoss 4.0.3 doesn't use JBossMessaging, it uses JBoss MQ. Please post in the JBoss MQ forum, this the JBoss Messaging forum :)

  • 11. Re: Programmaticaly create queue
    Poonam Agarwal Newbie

    I was able to create queues using deployQueue from the JMX Web console....but when I code it.....
    I get InstanceNotFoundException (bean not registered) when I use the following code
    mbeanServer = MBeanServerFactory.createMBeanServer();
    ObjectName objName = new ObjectName("jboss.messaging:service=ServerPeer");
    mbeanServer.invoke(objName, "deployQueue",
    new Object[] { "anyname", null },
    new String[] { "java.lang.String", "java.lang.String"} );

    I am running the above code from a EJB Session bean in the same jboss server.
    I have done all the steps to replace a Jboss MQ instance to a JBM 1.4 in jboss 4.2.0.
    I have started the messaging server as I am able to perform this operation from jmx-web console...
    Can somebody help?
    -Poonam

  • 12. Re: Programmaticaly create queue
    Andy Taylor Master

    You need to look up the mbean server not create one.

  • 13. Re: Programmaticaly create queue
    Poonam Agarwal Newbie

    Thanks
    I could achieve the same by looking up the
    jmx/rmi/RMIAdaptor and then fire invoke() on it.
    I am now able to createQueue dynamically using this.