【问题标题】:Apache Camel timer route URI syntaxApache Camel 计时器路由 URI 语法
【发布时间】:2014-09-25 02:59:53
【问题描述】:

我有一个骆驼应用程序,其定时器路由定义如下:

String timerURI = "timer:/MyApplication?period=5m";

我意识到 URI 语法可能不正确。 Apache Camel 网站上显示的正确语法应该是:

String timerURI = timer://MyApplication?period=5m";

但是,我注意到日志中有一些奇怪的行为。在第一个实例中,我显示骆驼将 URI 记录为:

(route1) from(timer:///MyApplication?period=5m) --> bean[com.mypackage.....]

在第二种情况下,日志显示为:

(route1) from(timer://MyApplication?period=5m) --> bean[com.mypackage.....]

我尝试了第三个选项

String timerURI = timer:MyApplication?period=5m";

它在日志中显示为:

(route1) from(timer://MyApplication?period=5m) --> bean[com.mypackage.....]

当我使用单个 / 定义 URI 时,与第一种情况一样,我看到如下异常:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: direct: due to: Expected scheme-specific part at index 7: direct:
    at org.apache.camel.impl.DefaultCamelContext.normalizeEndpointUri(DefaultCamelContext.java:601)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:483)
    at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:63)
    at org.apache.camel.util.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:88)
    at org.apache.camel.processor.RecipientListProcessor.resolveEndpoint(RecipientListProcessor.java:223)
    at org.apache.camel.processor.RecipientListProcessor.createProcessorExchangePairs(RecipientListProcessor.java:163)
    at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:208)
    at org.apache.camel.processor.RecipientList.sendToRecipientList(RecipientList.java:153)
    at org.apache.camel.processor.RecipientList.process(RecipientList.java:112
::::::::::::::::::::::::::::::::
Caused by: java.net.URISyntaxException: Expected scheme-specific part at index 7: direct:
    at java.net.URI$Parser.fail(URI.java:2829)
    at java.net.URI$Parser.failExpecting(URI.java:2835)
    at java.net.URI$Parser.parse(URI.java:3038)
    at java.net.URI.<init>(URI.java:595)
    at org.apache.camel.util.URISupport.normalizeUri(URISupport.java:448)
    at org.apache.camel.impl.DefaultCamelContext.normalizeEndpointUri(DefaultCamelContext.java:599)
    ... 51 more

所以只有在我有单个 / 的第一个实例中,我看到了这个异常,但其他两个似乎没问题。更奇怪的是,错误不会经常重复。我从来没有在我的本地工作区看到它,但我在我的开发测试服务器和集成测试服务器中看到了两次。即使在此异常失败后,它也会在下一次计时器在 5 分钟后运行时工作。有谁知道骆驼是如何解释这些 URL 的以及为什么它失败了几次?

【问题讨论】:

  • Rishi - 您能否提供示例代码?我正在努力在我的代码中使用 from() API,不知道如何在 spring application-context.xml 中配置 camel-quartz?
  • @javaHelper:路由器类:String timerURI = timer://MyApplication?period=5m"; @Autowired private MyApplicationConsumerClass consumer; from(timerUrl) .bean(consumer, "processQueueOnTimer('queueTimer')"); 消费者类:@Component public class MyApplicationConsumerClass { public void processQueueOnTimer(String queueTimer, Exchange exchange) throws Exception { ... ... } }

标签: apache-camel


【解决方案1】:

不使用斜线,或使用双斜线。例如

"timer:foo"

"timer://foo"

那么当有双斜线的时候,Camel就认为这是没有斜线的,比如http://foo.com,可以在浏览器中输入http:foo.com。

如果您使用 1 或 3 个斜线,则该斜线将成为组件上下文路径的一部分。只有少数组件支持前导斜杠,例如文件/ftp组件,其中前导斜杠表示起始目录为/foo等。

【讨论】:

  • 有什么解释为什么 1 斜线除了少数几次之外大部分都有效吗?如果它无效,我会一直预期错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多