Apache Camel 计时器路由 URI 语法 [英] Apache Camel timer route URI syntax

查看:34
本文介绍了Apache Camel 计时器路由 URI 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a camel application with a timer route defined like this:

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

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

I realized that the URI syntax is probably incorrect. The correct syntax as shown on the Apache Camel site should be:

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

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

However, I noticed some strange behavior in the logs. In the first instance I show camel logging the URI as:

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

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

In the second instance, the log shows as:

(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 时,如第一种情况,我看到如下异常:

When I defined the URI with a single /, as in the first case, I see an exception like this:

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 的,以及为什么它失败了那几次?

So only with the first instance when I had single /, I saw this exception but the other two seem to be fine. Even stranger though, the error doesn't repeat very often. I never see it my local workspace but I saw it twice in my Dev test server and once in the Integration test server. Even after failing with this exception, it works in the next time when the timer runs after 5 minutes. Does anyone know how camel is interpreting these URLs and why it failed those few times?

推荐答案

不要使用斜线,或者使用双斜线.例如

Use no slashes, or use double slashes. eg

"timer:foo"

"timer://foo"

然后当有双斜线时,Camel 认为这是没有斜线,例如 http://foo.com,可以在浏览器中输入 http:foo.com.

Then when having double slashes, then Camel regards this as no slashes, eg like http://foo.com, can be typed http:foo.com in the browser.

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

If you use 1 or 3 slashes, then that slash becomes part of the context-path for the component. Only a few components support a leading slash, such as the file/ftp components where a leading slash denotes the starting directory is /foo etc.

这篇关于Apache Camel 计时器路由 URI 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆