java Camel Direct 端点异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30192976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:38:21  来源:igfitidea点击:

Camel Direct end-point exception

javaapache-camel

提问by keen_girl

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 :(

我收到一个异常“端点上没有可用的消费者”。这是一个简单的路由 & 我已经做了我能做的一切 - 现在花了 10 多个小时:(

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 Adam Hawkes

By default, the directcomponent expects that there is a matching consumer for every producer. Note the new configuration option failIfNoConsumersshown 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:

默认情况下,direct组件期望每个生产者都有一个匹配的消费者。请注意Camel 文档中failIfNoConsumers显示的新配置选项。没有消费者,交易所在您路线的尽头无处可去。您可以考虑添加另一个这样的路线:

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

回答by DataHacker

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....

当您忘记启动 Camel 上下文并像我一样创建生产者/消费者模板时,也会抛出....

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

花了我半天时间才找到:-(,所以不要忘记

context.start()

回答by user1983048

If you have multiple camelContext and you have not mentioned correct camelContext id then also you will get this exception.

如果您有多个camelContext 并且您没有提到正确的camelContext id,那么您也会收到此异常。

回答by gnanagurus

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 .

您甚至可以在 from 端点之后添加一个日志端点并终止路由。