10

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?

1
  • Does .stop(); work ? Commented Aug 16, 2018 at 10:42

4 Answers 4

8

You can see if the Stub component can help

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

Example:

from("...") .to("stub:nowhere"); 
Sign up to request clarification or add additional context in comments.

3 Comments

Works beautifully.
Can you use the DLC EIP for that? See enterpriseintegrationpatterns.com/patterns/messaging/… > When a messaging system determines that it cannot or should not deliver a message, it may elect to move the message to a Dead Letter Channel.
As someone suggested. .stop(); is better after capturing what you need. Note that stub causes memory leak issues as it holds on to the messages sent to it. If you still need to use stub, consider discardIfNoConsumers option.
3

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") 

3 Comments

So, I will need to delete a potentially large file when processing is complete? There is no way to just do the equivalent of sending data to /dev/null?
It looks like I can do something like to("log:trash?level=OFF").
Indeed. Otherwise, just tune your logging system: - reduce debug level of the target category (not to dump content) - use a rolling file appender policy (keep only 2 last days to reduce disk space consumption)
1

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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.