Agent的实现:
package com.easyway.esb.mule.mbean; import org.mule.api.MuleException; import org.mule.api.agent.Agent; import org.mule.api.lifecycle.InitialisationException; import java.util.Collections; import java.util.List; /** 必须继承自org.mule.api.agent.Agent接口. * Mock agent */ public class AutoTaskAgent implements Agent { private String frobbit; public String getName() { return "Test Agent"; } public void setName(String name) { // nothing to do } public String getDescription() { return "Test JMX Agent"; } public void initialise() throws InitialisationException { // nothing to do } public void start() throws MuleException { // nothing to do } public void stop() throws MuleException { // nothing to do } public void dispose() { // nothing to do } public List<Class<? extends Agent>> getDependentAgents() { return Collections.emptyList(); } public String getFrobbit() { return frobbit; } public void setFrobbit(String frobbit) { this.frobbit = frobbit; } }
mule-mbean-config.xml的配置
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:management="http://www.mulesoft.org/schema/mule/management" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/management http://www.mulesoft.org/schema/mule/management/current/mule-management.xsd"> <management:jmx-server> <management:connector-server url="service:jmx:rmi:///jndi/rmi://localhost:9998/server" rebind="false" /> <management:credentials> <spring:entry key="a" value="b"/> <spring:entry key="c" value="c"/> </management:credentials> </management:jmx-server> <management:jmx-log4j/> <management:jmx-mx4j-adaptor jmxAdaptorUrl="http://127.0.0.1:8000"/> <custom-agent name="test-custom-agent" class="com.easyway.esb.mule.mbean.AutoTaskAgent"> <spring:property name="frobbit" value="woggle"/> </custom-agent> <management:jmx-notifications/> <management:log4j-notifications/> <management:chainsaw-notifications chainsawPort="8080" chainsawHost="127.0.0.1"/> </mule>
jmx测试代码:
public class MuleAgentMain { public static void main(String[] args) throws Exception, ConfigurationException { String configFile = "mule-mbean-config.xml"; String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext muleContext = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); muleContext.start(); Agent agent = muleContext.getRegistry().lookupObject(JmxAgent.class); System.out.println(agent.getClass()); JmxAgent jmxAgent = (JmxAgent) agent; System.out.println(jmxAgent.isCreateServer()); System.out.println(jmxAgent.isLocateServer()); System.out.println(jmxAgent.isEnableStatistics()); System.out.println(jmxAgent.getConnectorServerUrl()); agent = muleContext.getRegistry().lookupAgent("jmx-log4j"); System.out.println(agent.getClass()); agent = muleContext.getRegistry().lookupAgent("jmx-mx4j-adaptor"); System.out.println( agent.getClass()); Mx4jAgent mx4jAgent = (Mx4jAgent) agent; System.out.println(mx4jAgent.getJmxAdaptorUrl()); agent = muleContext.getRegistry().lookupAgent("jmx-notifications"); System.out.println(agent.getClass()); agent = muleContext.getRegistry().lookupAgent("log4j-notifications"); System.out.println(agent.getClass()); agent = muleContext.getRegistry().lookupAgent("chainsaw-notifications"); System.out.println(agent.getClass()); Log4jNotificationLoggerAgent lnlAgent = (Log4jNotificationLoggerAgent) agent; System.out.println(lnlAgent.getChainsawPort()+" "+lnlAgent.getChainsawHost()); agent = muleContext.getRegistry().lookupAgent("test-custom-agent"); AutoTaskAgent autoTaskAgent=(AutoTaskAgent) agent; System.out.println( autoTaskAgent.getFrobbit()); autoTaskAgent.setFrobbit("aaa"); agent = muleContext.getRegistry().lookupAgent("test-custom-agent"); System.out.println(((AutoTaskAgent)agent).getFrobbit()); } }
相关推荐
Mule ESB 是一个轻量级的基于java的企业服务总线和集成平台, 使得开发人员可以快速,简单的连接多个应用, 使得它们可以交换数据。 Mule ESB 容易集成现有异构系统,包括:JMS, Web Services, JDBC, HTTP, 等. ESB...
文档主要介绍了Mule ESB的使用方法,并结合具体实例加深对ESB的理解,对新手很有帮助哦!
Mule ESB 项目在Linux中的部署与开发与应用案例
MuleESB是一个基于Java的轻量级企业服务总线和集成平台,允许开发人员快速便利地连接多个应用,并支持应用间的数据交换。MuleESB支持集成现有系统而无论其底层采用何种技术,如JMS、WebServices、JDBC、HTTP以及其他...
Mule ESB应用部署 Mule ESB应用的目录结构,配置文件说明
MuleESB3.0 属于轻量级的消息框架和整合平台,mule云
ESB原理及Mule ESB实践
mule,mule esb,Mule,ESB
MuleESB集成webservice+restful(sprintboot+mybatis+mysql)+activeMQ+javamail,五天的研究成果,集成了我所关注的点,希望有更多的朋友一起学习进步。
mule esb 项目 例子 入门
mule esb开发手册
mule esb mule esb 开发工具
MuleEsb开源框架简介.pdf
mule esb mule esb打包手册文档
企业服务总线(Mule ESB)的研究与实现
mule esb 的 简单介绍, 以及一些主要特性的介绍
MuleESB_3.0_中文教程
mule esb 3 user guider: 社区成熟,文档丰富的开源esb mule用户手册