使用jmx对weblogic进行动态的配置(源代码)

使用jmx对weblogic进行动态的配置(源代码),第1张

对weblogic进行配置一般是通过console控制台来进行配置的 但有的时候 需要自己在程序中需要进行动态的配置 比如增加队列 显示队列 或者配置数据源 改写写config xml 是可以达到动态配置的效果的 但bea不推荐这样做 而且这样做需要重新启动服务器 怎么样既动态的配置 又不重新启动服务器呢?笔者查询了weblogic的网站 了解到有两种方法动态的配置( )可以使用weblogic Admin命令(文档地址 ) ( )使用weblogic是用jmx编程来进行管理 通过jmx来对weblogic中的组件进行动态的配置 jmx的文档地址 如果使用这种方法 要将weblogic jar配置到CLASSPATH环境变量中(因为weblogic的jmx类是放在weblogic jar中的)本人写了一份代码 对Queue进行管理 包括JMSQueue的增加 删除 和显示 我的config xml文件如下 <JMSServer Name= MessageCenterServer Store= MyJmsSave Targets= myserver TemporaryTemplate= MyJMSTemplate ><JMSQueue CreationTime= JNDIName= CenterQueue Name= CenterQueue Template= MyJMSTemplate /><JMSQueue CreationTime= JNDIName= que Name= que Template= MyJMSTemplate /><JMSQueue CreationTime= JNDIName= que Name= que Template= MyJMSTemplate /><JMSQueue CreationTime= JNDIName= queue Name= queue /></JMSServer>代码如下 package messagecenter;/ <p>Title: 消息中心</p> <p>Description: 对消息队列进行维护</p> @author 张荣斌 @version /import java util ;import java util regex Pattern;import javax naming Context;import weblogic jndi Environment;import weblogic management MBeanHome;import weblogic management runtime ServletRuntimeMBean;import weblogic management runtime ApplicationRuntimeMBean;import weblogic management runtime WebAppComponentRuntimeMBean;import weblogic management runtime ComponentRuntimeMBean;import weblogic jms extensions ;import weblogic management RemoteMBeanServer;import javax management ObjectName;import javax management QueryExp;public class JMSQueueMaintain {public static final String WEBLOGIC_URL = t ://localhost: ;public static final String WEBLOGIC_USER= system ;public static final String WEBLOGIC_PASSWORD = ;public static final String WEBLOGIC_JMSSERVER = MessageCenterServer ; //JMS服务器的名字 可以看到我的config xml<JMSServerName= MessageCenterServer Store= MyJmsSave 这一行public JMSQueueMaintain() {}/ 得到initial context/private static Context getCtx(String url String username String password) throws Exception{Environment env = new Environment();env setProviderUrl(url);env setSecurityPrincipal(username);env setSecurityCredentials(password);return env getInitialContext();}/ 得到the Admin MBean Home/private static MBeanHome getMBeanHome(String url String username String password) throws Exception{return (MBeanHome) getCtx(url username password) lookup(MBeanHome ADMIN_JNDI_NAME);}/ 增加队列/public static void addQueue(String queuename) throws Exception{Context ctx = getCtx(WEBLOGIC_URL WEBLOGIC_USER WEBLOGIC_PASSWORD);JMSHelper createPermanentQueueAsync(ctx WEBLOGIC_JMSSERVER queuename queuename);}/ 删除队列/public static void deleteQueue(String queuename) throws Exception{Context ctx = getCtx(WEBLOGIC_URL WEBLOGIC_USER WEBLOGIC_PASSWORD);JMSHelper deletePermanentQueue(ctx WEBLOGIC_JMSSERVER queuename);}/ 得到所有的队列名/public static Vector getQueuenames() throws Exception{Vector vect = new Vector();MBeanHome home = getMBeanHome(WEBLOGIC_URL WEBLOGIC_USER WEBLOGIC_PASSWORD);RemoteMBeanServer homeServer = null;QueryExp query = null;homeServer = home getMBeanServer();Set JMSMBeans = homeServer queryNames(new ObjectName( mydomain:JMSServer= +WEBLOGIC_JMSSERVER+ Type=JMSQueue ) query);//where query could be any object that implements the JMX//javax managementQueryExpfor (Iterator itr = erator(); itr hasNext(); ) {ObjectName mbean = (ObjectName)itr next();if(!mbean getKeyProperty( Name ) equals( CenterQueue )){vect addElement(mbean getKeyProperty( Name ));}}return vect;}public static void main(String[] args) {JMSQueueMaintain JMSQueueMaintain = new JMSQueueMaintain();try{System out println(JMSQueueMaintain getQueuenames());JMSQueueMaintain addQueue( queue );JMSQueueMaintain deleteQueue( queue );System out println(JMSQueueMaintain getQueuenames());}catch(Exception e){}}} lishixinzhi/Article/program/Java/ky/201311/28614

缺省安装中使用DemoIdentityjks和DemoTrustjks KeyStore实现SSL,需要配置服务器使用Enable SSL,配置其端口,在产品模式下需要从CA获取私有密钥和数字证书,创建identity和trust keystore,装载获得的密钥和数字证书。可以配置此SSL连接是单向还是双向的。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/13485914.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-16
下一篇 2023-08-16

发表评论

登录后才能评论

评论列表(0条)

保存