Contact Us 1-800-596-4880

Catch-All Strategies

You can configure a catch-all strategy that will be invoked if no routing path can be found for the current message. An inbound or outbound endpoint can be associated with a catch-all strategy so that any orphaned messages can be caught and routed to a common location. For detailed information on the elements you configure for catch-all strategies, see Catch-all Strategy Configuration Reference.

For example:

<service name="dataService">
    <inbound>
        <inbound-endpoint address="vm://in2" connector-ref="vmQueue">
            <string-to-byte-array-transformer/>
        </inbound-endpoint>

        <selective-consumer-router>
            <payload-type-filter expectedType="java.lang.Integer"/>
        </selective-consumer-router>

        <custom-forwarding-catch-all-strategy class="org.mule.test.usecases.routing.InboundTransformingForwardingCatchAllStrategy">
             <outbound-endpoint address="vm://catchall" connector-ref="vmQueue">
                 <string-to-byte-array-transformer/>
             </outbound-endpoint>
         </custom-forwarding-catch-all-strategy>
    </inbound>
    ...
    <outbound>
        <filtering-router transformer-refs="TestCompressionTransformer">
            <outbound-endpoint address="test://appleQ2" name="TestApple-Out" />
            <payload-type-filter expectedType="java.lang.String" />
        </filtering-router>
        <custom-catch-all-strategy class="org.mule.tck.testmodels.mule.TestCatchAllStrategy" />
    </outbound>
    ...
</service>

Following are descriptions of the different catch-all strategies you can use.

Forwarding

This catch-all strategy is used to forward the message to an endpoint that is configured if no outbound routers match.

<forwarding-catch-all-strategy>
  <jms:outbound-endpoint queue="error.queue"/>
</forwarding-catch-all-strategy>

Custom Forwarding

This catch-all strategy is the same as the default forwarding catch-all strategy, but it allows you to specify a custom implementation to use by configuring the class attribute. You can also configure additional optional properties.

<custom-forwarding-catch-all-strategy class="org.my.CustomForwardingCatchAllStrategy">
  <jms:outbound-endpoint queue="error.queue"/>
  <spring:property key="myProperty" value="myValue"/>
</forwarding-catch-all-strategy>

Logging

This catch-all strategy does nothing with the message and simply logs a warning indicating that the message was not dispatched because there was no routing path defined.

<logging-catch-all-strategy/>

Custom

This catch-all strategy allows you to use a custom class to perform whatever behavior you require. To implement a custom catch-all strategy that forwards the message to an endpoint, you should used the custom forwarding catch-all strategy instead.

<custom-catch-all-strategy/>