JMS(Jboss Messaging)的一點使用心得(七)JBoss invoke-動態創建Queue或者Topic

JBoss是通過配置文件構建的,但是我們可以用代碼通過Invoke的方式修改這些MBean。其實,<http://localhost:8080/jmx-console/>下的所有MBean都可以用這種方式修改,比如說動態創建Queue或者是Topic.
    public void createQueueInJboss(String queueName) {
        
try {
            Context context;
            Hashtable 
<String, String> jndi = new Hashtable <String, String>();
            jndi.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.jnp.interfaces.NamingContextFactory");
            jndi.put(Context.URL_PKG_PREFIXES, 
"org.jboss.naming:org.jnp.interfaces");
            jndi.put(Context.PROVIDER_URL, 
"172.60.0.126:1099");

            context 
= new InitialContext(jndi);
            MBeanServerConnection server 
= (MBeanServerConnection) context.lookup("jmx/invoker/RMIAdaptor");
            server.invoke(
new ObjectName("jboss.messaging:service=ServerPeer"),
                          
"deployQueue",
                          
new Object[] {queueName, "queue/" + queueName},
                          
new String[] {"java.lang.String""java.lang.String"});
        }
 catch (Exception e) {
            e.printStackTrace();
        }

    }

發佈了29 篇原創文章 · 獲贊 1 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章