3 Replies Latest reply on Apr 2, 2009 1:33 PM by russinb

    programmatically deploy clustered topic

      How do I programmatically deploy a clustered topic in v1.3 ?

      I'm currently using;

      MBeanServerConnection mBeanServer = MBeanServerLocator.locateJBoss();
      ObjectName objName = new ObjectName("jboss.messaging:service=ServerPeer");
      MBeanServerInvocationHandler.newProxyInstance(mBeanServer, objName, ServerPeerMBean.class, false);
      serverPeerMBean.deployTopic(name,jndiName);


      thanks in advance

      James

        • 1. Re: programmatically deploy clustered topic
          timfox

          There's no way of doing this using the JMX API in a single call - you'll need to connect to each node and deploy it individually.

          Or you could write some code that uses the farm service to deploy to all nodes (like when you drop the deployment descriptor in the farm directory).

          • 2. Re: programmatically deploy clustered topic

            Hi Tim,

            Thanks for the suggestion I might have a play with the farm service in the future.

            If anyone is interested, for now I use something like the following, it seems to do what I need;

            public void addTopicMessageListener(String jndiName, MessageListener messageListener) throws NamingException, JMSException, Exception {
            
             String topicName = jndiName.substring(jndiName.lastIndexOf('/')+1);
            
             try{
             //CHECK IF THE TOPIC IS DEPLOYED LOCALLY
             Topic topic = (Topic)haInitialContext.lookup(jndiName);
             log("OK Topic " + jndiName+ " exists");
            
             //I think this will throw an exception if the Topic is on a remote machine
             MessageConsumer subscriber = localJMSSession.createConsumer(topic);
             subscriber.setMessageListener(messageListener);
             log("Lstener "+messageListener+" add to topic " + topicName);
             }catch(Exception e){
             log("NO TOPIC, OR TOPIC WAS ON A REMOTE ONLY WHEN ADDING MessageListener TO topic "+topicName+". "+e.getMessage());
            
             //DEPLOY THE TOPIC ON THIS MACHINE
             MBeanServerConnection mBeanServer = MBeanServerLocator.locateJBoss();
             ServerPeerMBean serverPeerMBean = (ServerPeerMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, new ObjectName("jboss.messaging:service=ServerPeer"), ServerPeerMBean.class, false);
             serverPeerMBean.deployTopic(topicName, jndiName);
            
             //MAKE IT CLUSTERED
             ObjectName on = new ObjectName("jboss.messaging.destination:service=Topic,name="+topicName);
             MBeanInfo mbeanInfo = MBeanServerLocator.locateJBoss().getMBeanInfo(on);
             MBeanServerLocator.locateJBoss().invoke(on, "stop", null, null);
             MBeanServerLocator.locateJBoss().setAttribute(on, new Attribute("Clustered", true));
             MBeanServerLocator.locateJBoss().invoke(on, "start", null, null);
            
             //TRY TO ADD THE messageListenerAgain
             Topic topic = localJMSSession.createTopic(topicName);
             MessageConsumer subscriber = localJMSSession.createConsumer(topic);
             subscriber.setMessageListener(messageListener);
             log("Successfully added listener "+messageListener+" to distributed topic " + topicName);
             }
            
            }




            cheers

            James





            • 3. Re: programmatically deploy clustered topic

              I have not had luck with stopping a queue, changing the clustered attribute and then restarting the queue. The message in the exception tells me the queue must be redeployed when changing the clustering setting. This post is a bit old and the APIs seemed to have changed a bit (I'm using JBM 1.4). Would the proper order be to:
              deploy the queue/topic
              stop the queue/topic
              set the clustered attribute
              undeploy the queue/topic
              deploy the queue/topic
              start the queue/topic