有没有办法将onCompletion上下文范围的“处理程序”添加到 Camel 上下文?Camel onCompletion 文档展示了如何使用 Spring XML DSL 来完成此操作,但我一直无法找到以编程方式完成此操作的方法。
如何访问 Apache Camel Rest 模块中的 PathVariables?
我定义了这样的路线(遵循文档中的“使用基本路径” ):
rest("/customers/")
.get("/{id}").to("direct:customerDetail")
Run Code Online (Sandbox Code Playgroud)
如何{id}在以下路线中控制 -Parameter?
基本上我想知道骆驼提供什么而不是@PathVariable(见下面的例子)
@RequestMapping(value="/customers/{id}", method = RequestMethod.GET)
public Customer customerDetail(@PathVariable String cId) {
return getCustomer(cId);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用camel-amqp(2.17版)组件在我的camel路由中连接到rabbitmq。
我已将其配置如下:
@Bean
CachingConnectionFactory jmsCachingConnectionFactory(){
JmsConnectionFactory pool = new JmsConnectionFactory();
pool.setRemoteURI("amqp://127.0.0.1:5672");
pool.setUsername("guest");
pool.setPassword("guest");
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(pool);
return cachingConnectionFactory;
}
@Bean
JmsConfiguration jmsConfig(){
JmsConfiguration configuration = new JmsConfiguration();
configuration.setConnectionFactory(jmsCachingConnectionFactory());
// configuration.setCacheLevelName("CACHE_CONSUMER");
return configuration;
}
@Bean
AMQPComponent amqp(){
AMQPComponent component = new AMQPComponent();
component.setConfiguration(jmsConfig());
return component;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
javax.jms.JMSException: 远程主机在 org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:66) ~[qpid-jms-client-0.8.0.jar 强制关闭现有连接:0.8.0]
在我的 rabbitmq 日志中,我可以看到以下我无法理解的消息
*
** Reason for termination ==
** {function_clause,
[{rabbit_amqp1_0_link_util,'-outcomes/1-lc$^0/1-0-',
[{list,
[{symbol,<<"amqp:accepted:list">>},
{symbol,<<"amqp:rejected:list">>},
{symbol,<<"amqp:released:list">>},
{symbol,<<"amqp:modified:list">>}]}],
[{file,"src/rabbit_amqp1_0_link_util.erl"},{line,49}]},
{rabbit_amqp1_0_link_util,outcomes,1,
[{file,"src/rabbit_amqp1_0_link_util.erl"},{line,49}]},
{rabbit_amqp1_0_outgoing_link,attach,3,
[{file,"src/rabbit_amqp1_0_outgoing_link.erl"},{line,41}]},
{rabbit_amqp1_0_session_process,with_disposable_channel,2,
[{file,"src/rabbit_amqp1_0_session_process.erl"},{line,377}]},
{rabbit_amqp1_0_session_process,handle_control,2,
[{file,"src/rabbit_amqp1_0_session_process.erl"},{line,197}]}, …Run Code Online (Sandbox Code Playgroud) 我有一个关于 Apache Camel 的问题。我无法找到是否处理了多播。如果是交易,交易是如何实现的?什么是交易边界?
Camel Spring Boot 扫描 RouteBuilder 的 Spring 上下文。˚F ROM中的文档:
Camel 自动配置从 Spring 上下文中收集所有 RouteBuilder 实例,并自动将它们注入到提供的 CamelContext 中。这意味着使用 Spring Boot starter 创建新的 Camel 路由就像将 @Component 注释类添加到类路径一样简单
有没有办法控制这个:包含/排除包或类。
我想注释某些 RouteBuilders 并让 Camel 排除它们。我的意图是稍后将它们动态添加到 CamelContext 中。
我正在尝试构建一个模块以插入 Spring Boot 应用程序。这个模块应该公开一些 REST 端点,我正在尝试用 Camel 构建它们,因为我不想向 web.xml 等添加内容。
restConfiguration().component("servlet")
.contextPath("/my")
.apiContextPath("/api-doc")
.apiProperty("api.title", "My REST API")
.apiProperty("cors", "true")
.apiContextRouteId("my-api")
.bindingMode(RestBindingMode.json);
rest("/my").description("My REST Services")
.get("foo/{id}").route().routeId("foo")
.to("direct:foo");
from("direct:foo")
.process(new FooParamParser())
.log("Done");
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,不是在 /my/foo/123?status=abc 我必须在 /camel/my/foo/123?status=abc 打它。
它这样做是因为它默认使用 Camel Servlet 作为来自 DSL 的 REST 端点,我对此很好,但我不希望它把“/camel”放在我的路径的开头。我应该注意到,无论有没有.component("servlet")
有什么办法可以改变吗?
通常,如果我们使用 Java DSL 开发 Java Camel 应用程序,则很难监控 Camel 路由。为了检查路由是否正在运行,我们需要开发一个额外的监控应用程序。
但是 Hawtio 在这方面减轻了我们的工作。如果您的项目是 Web 应用程序项目,那么 Hawtio 已经为它提供了骆驼组件。因此,无需任何额外的努力,它将直接工作。
但是对于 Java 应用程序,它没有显示路由。
我正在使用 Apache Camel 来协助捕获第三方软件包发出的消息数据。在这个特定的例子中,我只需要捕捉软件产生的东西,另一端没有接收器(真的没有“端”去)。
因此,我尝试设置一条只有“from”端点而没有“to”端点的路由。显然这是不正确的用法,因为我收到以下异常:
[2018-08-15 11:08:03.205] ERROR: string.Launcher:191 - Exception
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> From[mina:udp://localhost:9877?sync=false] <<< in route: Route(route1)[[From[mina:udp://localhost:9877?sync=false]] -... because of Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1063)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:974)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3301)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3024)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2854)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2850)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2873)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2850)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2819)
at {removed}.Launcher.startCamel(Launcher.java:189)
at {removed}.Launcher.main(Launcher.java:125)
Caused by: java.lang.IllegalArgumentException: Route route1 has no output …Run Code Online (Sandbox Code Playgroud) 我有一组 Camel 路由配置为读取和写入 RabbitMQ 队列,或多或少是这样的:
from("rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueue}&routingKey=${it.rabbitMQQueue}&SOME_MORE_PROPERTIES")
.log("Read message from queue ${it.rabbitMQQueue}")
.routeId(it.rabbitMQQueue)
.noAutoStartup()
.bean(it.rabbitMQBean)
.choice()
.`when`(PredicateBuilder.and(simple("$myCondition"), isNotNull(body())))
.split(body())
.toD("rabbitmq:$rabbitMQVhost?connectionFactory=#customConnectionFactory&queue=${it.rabbitMQQueueDestination}&autoDelete=false&routingKey=${it.rabbitMQQueueDestination}&bridgeEndpoint=true")
.endChoice()
.otherwise()
end()
Run Code Online (Sandbox Code Playgroud)
SOME_MORE_PROPERTIES基本上在哪里autoDelete=false&autoAck=false和一些消息预取设置。
我的 ConnectionFactory 是一个org.springframework.amqp.rabbit.connection.CachingConnectionFactory.
每当消息进入我的源队列时,就会启动一个线程来处理它;然而,处理完成后,它挂在等待状态,永远不会被释放或终止,所以我的应用程序内存在一段时间后饱和,垃圾收集器对此无能为力。
运行一段时间后,我的应用程序基本处于这种状态:
如果我手动重新启动路由,线程将终止并释放内存。
我的路由配置是否有什么错误导致线程无法正确终止?
我想避免每隔一段时间编写一个石英作业来重新启动路由。
编辑:我最近也从 Camel 2.24.0 更新到 Camel 3 的最新 RC,但问题仍然存在。
我在 com.comp.myapp.routes 下的项目中定义了多个路由类。为了测试这些,我正在模拟最终路线并检查/比较收到的交付。
例如说我有以下路线:
public class MyRoute1 extends RouteBuilder {
public void configure() throws Exception {
//Route_1 code
}
}
public class MyRoute2 extends RouteBuilder {
public void configure() throws Exception {
//Route_2 code
}
}
....
...//some route impl
..
public class MyRouteN extends RouteBuilder {
public void configure() throws Exception {
//Route_N code
}
}
Run Code Online (Sandbox Code Playgroud)
现在对于所有这些路由,我编写的测试用例似乎相同。先嘲讽一下。
模拟MyRoute1:
public class MyRoute1_Mock extends RouteBuilder {
public void configure() throws Exception {
from("direct:sampleInput")
.log("Received Message is ${body} and Headers …Run Code Online (Sandbox Code Playgroud) apache-camel ×10
java ×5
rabbitmq ×2
amqp ×1
hawtio ×1
junit ×1
kotlin ×1
monitoring ×1
rest ×1
spring-boot ×1
unit-testing ×1
web-services ×1