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();
}
}
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();
}
}