<component class="org.my.ComponentImpl"/>
...
<pooled-component class="org.my.ComponentImpl"/>
Configuring Components
Components contain the business logic for working with the message passed through Mule ESB. A component can be any type of object, including a Spring bean, POJO, script, web service. or REST call.
Because they are highly specific to your implementation, you will typically [create your own custom components], or simply use an existing POJO. Mule also ships with some standard components you can use or extend as needed. This page describes how to configure the different types of components.
For detailed information on the elements you configure for components, see Component Configuration Reference
Simple Components
There are several simple components included with Mule that are useful for testing or bypassing component execution.
Configuration Element | Description |
---|---|
<log-component/> |
Logs component invocations, outputting the received message as a string. This component does not return a response. |
<echo-component/> |
Extends the log component to log and echo the incoming message. The message is transformed before being returned, so transformations on inbound endpoints will be applied. |
<null-component/> |
Throws an exception when invoked. This is useful for testing use cases that use a forward consumer inbound router. |
<test:component/> |
Configures the |
Java Components
Java components specify a Java class to be used as the component or configure a reference to an implementation in a container such as Spring. They also configure the way in which Mule should manage the Java component’s life-cycle, invoke it, and (if pooled) manage the pool of instances.
Java components can be configured quickly and easily by simply specifying the component implementation class name on the <component>
or <pooled-component>
element. The <pooled-component>
element allows you to establish a pooling profile for the flow (see Tuning Performance). In both cases, the PrototypeObjectFactory
will be used by default and a new object instance will be created for each request of (for pooled components) for each new object in the pool.
Alternatively, you can explicitly specify object factories, such as the SingletonObjectFactory
that creates a single instance of the object:
<component>
<singleton-object class="org.my.ComponentImpl"/>
</component>
The explicit syntax is required instead of the shortcut <component class>
syntax if you add interceptor to the component. For further configuration options and information on the default settings that are applied, see Configuring Java Components.
Other Components
These are several other components available that allow you to use different technologies such as web services for your components. These components are often included as part of transport or modules.
Configuration | Description |
---|---|
<http:rest-service-component/> |
Proxies a remote call to a REST-style web service. |
<cxf:wrapper-component/> |
Proxies a remote call to a web service using CXF. |
<script:component/> |
Configures a JSR-223 script for the component. |
Customizing Behavior with Interceptors
Mule interceptors are useful for attaching behaviors to multiple components. The interceptor pattern is often referred to as practical AOP (Aspect Oriented Programming), as it allows the developer to intercept processing on an object and potentially alter the processing and outcome. For complete information, see Using Interceptors.
Lifecycle
Components have a lifecycle like any other object in the Mule registry. Lifecycle can be configured by adding one or more lifecycle interfaces to your component. Since Mule 3.0 JSR-250 annotations can be used to configure intialise and destroy methods. The following list describes in order the lifecycle phrases for component objects.
Lifecycle examples
Full lifecycle:
org.my.ComponentImpl implements org.my.Component, org.mule.api.lifecycle.Lifecycle
{
public void initialise() throws InitialisationException { }
public void start() throws MuleException { }
public void stop() throws MuleException { }
public void dispose() { }
}
Initialise-only lifecycle:
org.my.ComponentImpl implements org.my.Component, org.mule.api.lifecycle.Initialisable
{
public void initialise() throws InitialisationException { }
}
Initialise/Dispose lifecycle using JSR-250 annotations
org.my.ComponentImpl implements org.my.Component
{
@PostConstruct
public void init() { }
@PreDestroy
public void destroy() { }
}