activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yanhongsan <xinchunli1...@163.com>
Subject Re: A question about the queue.
Date Tue, 08 Jul 2008 07:12:18 GMT



Brian Munroe-2 wrote:
> 
> 
> In the stock install of AMQ, it predefines a queue and topic.  You
> aren't referring to these, right?  
> 
> 
Yes, I am not referring to the predefined queue. I see the queue--Example.A.
The question is another queue I created with JMX. The code is: 

 public void addQueue(String queueName)
    {
    	MBeanServerConnection connection; 
    	try {
	connection = connect();
	createQueue(connection, queueName);			 
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    }
public MBeanServerConnection connect() 
        throws IOException {
        JMXConnector connector = null;
        MBeanServerConnection connection = null;
        String username = "";
        String password = "";
        Map env = new HashMap();
        String[] credentials = new String[] { username, password };
        env.put(JMXConnector.CREDENTIALS, credentials);
        try {
            connector = JMXConnectorFactory.newJMXConnector(new
JMXServiceURL(amqJmxUrl), env);
            connector.connect();
            connection = connector.getMBeanServerConnection();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        return connection; 
    }
public void createQueue(MBeanServerConnection conn,String queueName)throws
IOException
    {
    	 String brokerNameQuery =
"org.apache.activemq:BrokerName=localhost,Type=Broker";
         String addQueueOperationName = "addQueue";
         Object[] params = { queueName };
         String[] sig = { "java.lang.String" };
         
         doQueueCrud(conn, queueName, brokerNameQuery,
addQueueOperationName, params, sig, "creat");
    }
private void doQueueCrud(MBeanServerConnection conn, String queueName, 
            String brokerNameQuery, String operationName, Object[] params,
String[] sig, String verb)
    {
    	 ObjectName brokerObjName;
         
         try {
                 System.out.println( verb + "ing new Queue: [" + queueName +
"]");
                 brokerObjName = new ObjectName(brokerNameQuery); 
                 conn.invoke(brokerObjName, operationName, params, sig);
                 
                 System.out.println("Queue [" + queueName + "] has been " +
verb + "ed");
         } catch (MalformedObjectNameException e) {
             e.printStackTrace();
         } catch (NullPointerException e) {
             e.printStackTrace();
         } catch (InstanceNotFoundException e) {
             e.printStackTrace();
         } catch (MBeanException e) {
             e.printStackTrace();
         } catch (ReflectionException e) {
             e.printStackTrace();
         } catch (IOException e) {
			e.printStackTrace();
		}
    }
-- 
View this message in context: http://www.nabble.com/A-question-about-the-queue.-tp18312044p18333228.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message