Contact Us 1-800-596-4880

Using Mule Agents

An agent is a service that is associated with or used by Mule ESB but is not a Mule-managed component. Agents have the same lifecycle as the Mule instance they are registered with, so you can initialize and destroy resources when the Mule instance starts or is disposed.

Mule provides several agents for JMX support, including notifications and remote management. You can also create custom agents to plug any functionality into Mule, such as running functionality as a background process or embedding a server in Mule.

Configuring an Agent

Agents are defined in the Management module. To use an agent, specify the management namespace and schema, and then specify the properties for the agents you want to use. For example:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
  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/3.0/mule.xsd
  http://www.mulesoft.org/schema/mule/management
  http://www.mulesoft.org/schema/mule/management/3.0/mule-management.xsd">
  <management:jmx-default-config port="1098" registerMx4jAdapter="true" />

  <management:log4j-notifications logName="myMuleLog" logConfigFile="mule-log.txt"/>

  <management:chainsaw-notifications chainsawPort="8080" chainsawHost="127.0.0.1" />

  <management:publish-notifications endpointAddress="vm://myService" />

For a list of agents provided with Mule and how to configure them, see JMX Management. You can also create a custom agent as described below.

Creating Custom Agents

To create your own agent, your agent class must implement org.mule.api.agent.Agent.

You then configure your agent using the <custom-agent> element, which takes two attributes: name specifies a unique name for this agent, and class specifies the class where it’s defined. If your agent requires that you pass in properties, you can specify them as name/value pairs. Note that this element is now in the core Mule namespace.

For example:

<custom-agent name="test-custom-agent" class="org.mule.tck.testmodels.mule.TestAgent">
  <spring:property name="frobbit" value="woggle"/>
<custom-agent>