Joseph Gagnon
Joseph Gagnon

Reputation: 2115

Apache Camel route with no "to" endpoint

I am using Apache Camel to assist with capturing message data emitted by a third party software package. In this particular instance, I only need to capture what is produced by the software, there is no receiver on the other end (really no "end" to go to).

So, I tried to set up a route with just the "from" endpoint and no "to" endpoint. Apparently this is incorrect usage as I received the following exception:

[2018-08-15 11:08:03.205] ERROR: string.Launcher:191 - Exception
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> From[mina:udp://localhost:9877?sync=false] <<< in route: Route(route1)[[From[mina:udp://localhost:9877?sync=false]] -... because of Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1063)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:974)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3301)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3024)
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2854)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2850)
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2873)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2850)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2819)
    at {removed}.Launcher.startCamel(Launcher.java:189)
    at {removed}.Launcher.main(Launcher.java:125)
Caused by: java.lang.IllegalArgumentException: Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1061)
    ... 13 more

How do I set up a camel route that allows me to intercept (capture) the message traffic coming from the source, and not send it "to" anything? There is no need for a receiver. What would be an appropriate "to" endpoint that just drops everything it receives?

The exception suggestion of to("log:foo"). What does this do?

Upvotes: 9

Views: 7835

Answers (4)

simonalexander2005
simonalexander2005

Reputation: 4577

As it's not been written up as an answer yet, using .stop(); as the final call in the route definition can work as a better alternative to the other answers.

Upvotes: 0

р&#252;ффп
р&#252;ффп

Reputation: 5448

Apparently if you're under Linux or Unix, you can also redirect to /dev/null like in this example:

to( "file:/dev?fileName=null")

I am not sure it can be used on Windows but I don't think so.

Note that the syntax: to( "file:/dev/null") does not work as it point to a directory called null but with the fileName option it will work.

Upvotes: 1

vikingsteve
vikingsteve

Reputation: 40388

You can see if the Stub component can help

http://camel.apache.org/stub.html

Example:

from("...")
    .to("stub:nowhere");

Upvotes: 7

TacheDeChoco
TacheDeChoco

Reputation: 3913

The exception suggestion of to("log:foo"). What does this do?

It sends your route messages to an endpoint with a component of type log: (http://camel.apache.org/log.html) - component which basically dumps message contents (body and/or headers and/or properties) to your log file using appropriate log category.

If you just want to drop everything received, it's a good choice:

to("log:com.company.camel.sample?level=TRACE&showAll=true&multiline=true")

Upvotes: 3

Related Questions