Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel Direct end-point exception

I am having a simple problem. I am not able to read from a file end-point into a direct end-point. Below is the code snippet:

public class SampleTwo {


public static void main(String[] args) throws Exception {
    final CamelContext camelContext = new DefaultCamelContext();
    camelContext.start();
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {          
            from("file://target/inbox?noop=true&fileName=test.csv").to("direct://start"); //Fails with "No consumers available on endpoint" exception
            //from("file://target/inbox?noop=true&fileName=test.csv").to("file://target/outbox"); //Works

        }
    });

    Thread.sleep(1000*6000);

    // stop the CamelContext
  //  camelContext.stop();
}}

I get an exception "No consumers available on endpoint". It's a simple routing & I have done all I could -spent more than 10hours now :(

Please help ... following as stack trace (Trace enabled)

[hread #0 - file://target/inbox] EventHelper
TRACE Notifier: org.apache.camel.impl.DefaultRuntimeEndpointRegistry@99e74a is not enabled for the event: ID-01HW466539-57567-1431438054047-0-41 exchange failure: Exchange[test.csv] 
cause 
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://start]. Exchange[test.csv]
[hread #0 - file://target/inbox] FileConsumer                   
TRACE Done processing file: GenericFile[test.csv] synchronously
[hread #0 - file://target/inbox] DefaultErrorHandler            
ERROR Failed delivery for (MessageId: ID-01HW466539-57567-1431438054047-0-42 on ExchangeId: ID-01HW466539-57567-1431438054047-0-41). Exhausted after delivery attempt: 
1 caught:
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://start]. Exchange[test.csv]

Message History

--------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                              Elapsed (ms)
[route1            ] [route1            ] [file://target/inbox?fileName=test.csv&noop=true                               ] [         3]
[route1            ] [to1               ] [direct://start                                                                ] [         0]

Exchange

---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id                  ID-01HW466539-57567-1431438054047-0-41
ExchangePattern     InOnly
Headers             {breadcrumbId=ID-01HW466539-57567-1431438054047-0-42, CamelFileAbsolute=false, CamelFileAbsolutePath=C:\folder\eclipse-ws-march\camelsampletwo\target\inbox\test.csv, CamelFileContentType=null, CamelFileLastModified=1431426831841, CamelFileLength=45, CamelFileName=test.csv, CamelFileNameConsumed=test.csv, CamelFileNameOnly=test.csv, CamelFileParent=target\inbox, CamelFilePath=target\inbox\test.csv, CamelFileRelativePath=test.csv, CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType            org.apache.camel.component.file.GenericFile
Body                [Body is file based: GenericFile[test.csv]]]

Stacktrace

---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://start]. Exchange[test.csv]
like image 906
keen_girl Avatar asked May 12 '15 13:05

keen_girl


People also ask

What is direct endpoint in camel?

The direct: component provides direct, synchronous invocation of any consumers when a producer sends a message exchange. This endpoint can be used to connect existing routes in the same camel context.

How do camels handle exceptions?

Using onException to handle known exceptions is a very powerful feature in Camel. You can mark the exception as being handled with the handle DSL, so the caller will not receive the caused exception as a response. The handle is a Predicate that is overloaded to accept three types of parameters: Boolean.

How do I retry failed messages forever?

If you configure the Dead Letter Channel to use maximumRedeliveries = -1 then Camel will retry forever. When you consume a message you can check the in message header org. apache.


1 Answers

By default, the direct component expects that there is a matching consumer for every producer. Note the new configuration option failIfNoConsumers shown in the Camel Documentation. Without a consumer, the exchange has nowhere to go at the end of your route. You may consider adding another route like this:

public class SampleTwo {


public static void main(String[] args) throws Exception {
    final CamelContext camelContext = new DefaultCamelContext();
    camelContext.start();
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {          
            from("file://target/inbox?noop=true&fileName=test.csv").to("direct://start"); 
            from("direct://start").to("file://target/outbox");  //ADDED

        }
    });

    Thread.sleep(1000*6000);
}}
like image 74
Adam Hawkes Avatar answered Oct 04 '22 14:10

Adam Hawkes