Stop

How can I stop routing a message?

image

Use a special filter to mark the message to be stopped.

Options

The Stop eip supports 0 options, which are listed below.

Name Description Default Type

note

Sets the note of this node.

String

description

Sets the description of this node.

String

disabled

Disables this EIP from the route.

false

Boolean

Exchange properties

The Stop eip has no exchange properties.

Using Stop

We want to stop routing a message if the message body contains the word Bye. In the Content-Based Router below we use stop in such a case.

Java
from("direct:start")
    .choice()
        .when(body().contains("Hello")).to("mock:hello")
        .when(body().contains("Bye")).to("mock:bye").stop()
        .otherwise().to("mock:other")
    .end()
.to("mock:result");
XML
<route>
  <from uri="direct:start"/>
  <choice>
    <when>
      <simple>${body} contains 'Hello'</simple>
      <to uri="mock:hello"/>
    </when>
    <when>
      <simple>${body} contains 'Bye'</simple>
      <stop/>
    </when>
    <otherwise>
      <to uri="mock:other"/>
    </otherwise>
  </choice>
</route>
YAML

In YAML you use an empty stop: {} node as shown:

- route:
    from:
      uri: direct:start
      steps:
        - choice:
            when:
              - steps:
                  - to:
                      uri: mock:hello
              - steps:
                  - to:
                      uri: mock:bye
                  - stop: {}
            otherwise:
              steps:
                - to:
                    uri: mock:other
        - to:
            uri: mock:result

Stopping Exchange from Java code

You can also mark an Exchange to stop being routed using the setRouteStop(true) method using Java code:

Exchange exchange = ...
exchange.setRouteStop(true);

See Also

See also the related Throw Exception EIP.