我正在使用Java DSL在Camel for Rabbit MQ中编写一个简单示例。
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("rabbitmq://localhost?exchange=logs&exchangeType=fanout")
.to("stream:out");
}
});
context.start();
此示例应阅读消息并打印出来。
但我收到以下错误:
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[rabbitmq://localhost?exchange=logs&excha... because of Failed to resolve endpoint: rabbitmq://localhost?exchange=logs&exchangeType=fanout due to: String index out of range: -1
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:180)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:778)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:2041)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1791)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1665)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1633)
at com.test.app.App.initCamelContext(App.java:29)
at com.test.app.App.main(App.java:15)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: rabbitmq://localhost?exchange=logs&exchangeType=fanout due to: String index out of range: -1
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:532)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:71)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:190)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:106)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:88)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:888)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:175)
... 8 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at java.lang.String.substring(String.java:1904)
at org.apache.camel.component.rabbitmq.RabbitMQComponent.createEndpoint(RabbitMQComponent.java:45)
at org.apache.camel.component.rabbitmq.RabbitMQComponent.createEndpoint(RabbitMQComponent.java:27)
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:123)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:512)
... 16 more
以下是我的pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rabbitmq</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>2.13.0</version>
</dependency>
有人可以帮我弄清楚丢失的部分吗?
答案 0 :(得分:1)
可能你需要尝试像
这样的东西rabbitmq://localhost/logs?exchangeType=fanout
答案 1 :(得分:0)
wonhee的建议应该解决你的问题。这是解释:
根据RabbitMQ Component documentation,正确的网址格式为:
rabbitmq://hostname[:port]/exchangeName?[options]
没有exchange
选项,而是交换名称直接是路径的一部分。
答案 2 :(得分:0)
ExchangeName不是一个选项,它是URI路径的一部分。我将更新RabbitMQComponent代码,为它抛出更有意义的异常。