简体   繁体   中英

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]

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);
}}

This Exception

org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://XXXXX

is also thrown when you forget to start your Camel context and create Producer/Consumer templates, like me....

Took me half a day to find out :-(, so don't forget

context.start()

如果你有多个camelContext并且你没有提到正确的camelContext id,那么你也会得到这个异常。

Why you are passing it to a direct ? If you don't have any consumers on direct ? May I know the use case ?

You can even just add a log endpoint after from endpoint and terminate the route .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM