Access Keys:
Skip to content (Access Key - 0)
Cancel    
Cancel   

Contents

Creating Message Processors

This page describes how to implement a message processor in a DevKit module and shows some examples.

Assumptions

The @Processor Annotation

The @Processor method annotation exposes a particular method of a DevKit module as a Message Processor.

Quick example:

The method myMethod can be invoked from Mule as follows:

The @Processor Annotation

Any public, instance method can be annotated with the @Processor and then be invoked from Mule. These methods can receive any number and type of arguments and have any return type.

Parameter

   Description

name

Optional. The xml name of the element that will invoke this processor. If not specified,
the name will be derived from the name of the method.

intercepting

Optional. Setting this value to true will trigger the generation of a Intercepting Message Processor rather than a Message Processor.

@Optional

Similar to an @Optional annotated instance variable, using the @Optional on a method parameter means that it will not be required to provide a value for this parameter when invoking this method from Mule.

Example:

Because the divisor parameter is not mandatory, executing the following will result in a exception because it will attempt to divide by zero (zero is default value for ints).

@Default

A parameter annotated with @Default will take this value if it not explicitly set. Using the previous example:

Because the divisor parameter has now a default value of 1, the following will execute normally and will will set the paylod to 50.

Defining an Intercepting Message Processor

An intercepting message processor handles Mule events intercepting another listener Message Processor. It is the intercepting message processor's responsibility to decide whether the processing should continue or not, that is, if the next message processor in the chain should be invoked.

When setting the intercepting parameter to true, the method must have a parameter of type org.mule.api.callback.SourceCallback.

Example:

Restrictions on @Processor

Some restrictions apply to the methods that can be annotated with @Processor:

  • cannot be static
  • cannot be non-public
  • cannot have parameters named with the word name
  • overloading is not supported

More information