Tag: apache camel

在Apache Camel应用程序中,unit testing如何注入模拟端点来代替真实端点?

我正在使用Apache Camel实现消息转换器模式 ,以使用来自RESTful端点的消息并将它们发送到AMQP端点。 封闭的应用程序基于Spring Boot,因此我使用Camel的“ spring-boot ”组件来集成这两个框架。 正如这个spring-boot链接中的文档所示,我在@Configuration -annotated类中实现了我的Camel路由,该类扩展了RouteBuilder : @Component public class MyRestToAmqpRouter extends RouteBuilder { @Override public void configure() throws Exception { from(“jetty:http://my-restful-url”) .process(exchange -> { // convert the message body from JSON to XML, take some // incoming header values and put them in the outgoing // body, etc… }).to(“rabbitmq://my-rabbitmq-url”); } } […]

Apache Camel – 路由中的事务

我有一个关于Apache Camel的一般问题。 我无法确定聚合器是否已成交。 如果进行交易,如何实施交易以及汇总的速度有多快?

OSGi容器中的Camel:将InterceptStrategy应用于所有驼峰上下文

我有几个软件包(A,B和C)部署到OSGi容器,每个包含一个CamelContext和一些路由。 我有另一个包(M),带有一个CamelContext ,一个路由(用于收集监控数据)和一个InterceptStrategy bean。 我希望M中的InterceptStrategy bean能够自动应用于容器中的所有其他CamelContext (即A,B和C中的那些),而不必修改其他bundle。 最终,目标是将每个CamelContext数据窃听到M中的路由,而无需对A,B或C进行任何更改以显式路由Exchange 。 这种方法或类似的方法是否可行? 所有CamelContext都是使用Spring XML配置的。 更新:附加上下文 捆绑包A,B和C包含负责处理数据的核心产品。 Bundle M包含一个可选的监控工具,用于测量流经A,B和C的数据的某些参数。目前,添加可选工具需要更改A,B和C中的路由以添加额外的Processor以丰富Exchange与监控数据并在端点之前读取监控数据。 目标是能够将Bundle M放入已经过validation的A,B和C系统; 并使其自动应用于现有路由,而无需修改现有工作包的配置。 只要更改不会导致A,B和C依赖于M来运行(即,ABC必须仍然在没有M的情况下运行),对A,B和C进行修改以支持这一点是可以接受的。 如果有比使用拦截器更好的方法,我对此持开放态度。 主要目标是: 保持A,B和C与M分离(特别是在开发期间) 确保将M与A,B和C集成在一起尽可能简单 允许集成M而无需手动更改A,B或C.

如何以自动方式关闭独立的Apache Camel应用程序?

我正在尝试使用Apache Camel从FTP服务器下载和路由文件。 但是,文件只会在很长一段时间内添加到FTP服务器,因此程序连续运行似乎有点过于热心。 相反,我宁愿有一个每周运行的cronjob并处理已添加到服务器的任何新文件。 有没有办法让Camel在不再有任何新文件要处理后自动关闭? 我目前的mainfunction如下: public static void main (String[] args) throws Exception { org.apache.camel.spring.Main main = new org.apache.camel.spring.Main (); main.setApplicationContextUri (“applicationContext.xml”); main.enableHangupSupport (); main.run (args); } applicationContext.xml的有趣部分是:

Apache Camel:带有CxfEndpoint的RouteBuilder

你好! 我正在尝试使用Java DSL和RouteBuilder实现Camel路由。 我想从计时器端点发送到cxf端点。 码: public class MyRoute extends RouteBuilder { @Override public void configure() { CamelContext camelContext = getContext(); CxfEndpoint cxfEndpoint = new CxfEndpoint(); cxfEndpoint.setAddress(“http://localhost:8088/interface”); cxfEndpoint.setWsdlURL(“wsdl/contract.wsdl”); cxfEndpoint.setCamelContext(camelContext); cxfEndpoint.setDataFormat(DataFormat.PAYLOAD); try { camelContext.addEndpoint(“myEndpoint”, cxfEndpoint); } catch (Exception e) { e.printStackTrace(); } from(“timer://my-timer?fixedRate=true&period=500”) .transform(constant(“DummyBody”)) .to(“cxf://myEndpoint”); } } 这个路由被插入到使用Spring XML定义的camel上下文中(我有一些其他路由)。 问题: 我收到以下错误: karaf@root> Exception in thread “SpringOsgiExtenderThread-78” org.apache.camel.FailedToCreateProducerException: […]

使用带有OnException定义的adviceWith进行Camel路由测试

我有一个非常简单的Camel路由定义,它只包含一些OnException谓词来处理各自的exception和一些日志语句。 from(“hazelcast:seda:someQueue”) .id(“someQueueID”) .onException(CustomException.class) .handled(true) .log(LoggingLevel.WARN, “custom exception noticed”) .end() .onException(IOException.class, FileNotFoundException.class) .asyncDelayedRedelivery() .redeliveryDelay(3*1000*60) // 3 Minutes .maximumRedeliveries(3) .log(LoggingLevel.WARN, “io exception noticed”) .end() .onException(Exception.class) .log(LoggingLevel.WARN, “general exception noticed”) .end() .log(“Starting route”) .bean(TestBean.class) .log(“Finished route”); bean本身也很简单,只是检查一个header参数并抛出一个适当的exception public class TestBean { @Handler public void checkData(@Headers final Map headers) throws CustomException, IOException, Exception { Integer testVal = (Integer)headers.get(“TestValue”); […]

哪种Camel构造适合转换?

Apache Camel提供了几种执行数据转换的方法:Transform EIP的概念,自定义DataFormats,以及自定义类型转换器的容差。 我有一种情况需要从Camel路径内部进行非常复杂的转换。 我应该实现自己的Type Converter,我自己的DataFormat,还是应该实现org.apache.camel.Expression并将所有转换内容放在那里: public class MyTransformer implements Expression { @Override public T evaluate(Exchange arg0, Class arg1) { // … } } 我想我很困惑在何时何时使用你自己的Type Converter,何时使用.transform(myTransformer)处理器,或何时使用自定义DataFormat。 提前致谢!

如何使用camel创建数据源?

我刚开始学习Apache Camel。 我理解了路由和组件的基础知识。 现在,我想尝试连接到Oracle数据库,从一个特定的表读取记录,并使用File组件将这些记录写入File 。 要从数据库中读取,我假设我需要使用JDBC组件并提供dataSourceName 。 但是,我找不到有关如何使用camel创建dataSource的任何信息。 我发现与此主题相关的所有信息都使用Spring DSL示例。 我不使用Spring,我只需要使用简单的独立Java应用程序来测试它。 我正在使用JDK7u25和Apache Camel 2.12.1。 有人可以发布样本从oracle表中读取并写入文件吗? [编辑] 在网上查看了几个解决方案后,我开始了解以下两种方法: 骆驼独立运行。 这是我的代码: import javax.sql.DataSource; import org.apache.camel.main.Main; import org.apache.camel.builder.RouteBuilder; import org.apache.commons.dbcp.BasicDataSource; public class JDBCExample { private Main main; public static void main(String[] args) throws Exception { JDBCExample example = new JDBCExample(); example.boot(); } public void boot() throws Exception { […]

Apache Camel根据请求丰富了包含文件内容的消息

我正在实现RESTful服务(使用CXFRS组件),它应返回某些请求的文件。 每个文件都由其id和扩展名提取,即restfulservice.com/path/file/1/pdf 。 添加的每个文件永远不会更改。 提取后不应移动或删除文件,通常应同时访问它们。 这是我的Camel上下文的一部分: from(“direct:fetchFile”) .process(fetchFileProcessor) // set file.id & file.extension .bean(fileService, “fetchFile(${header.file.id}, ${header.file.extension})”) // set body to filename .setHeader(“CamelFileName”, simple(“${body}”)) .choice() .when(header(“file.extension”).isEqualTo(“xml”)) .pollEnrich(“file:///{{application.fileStorage.basePath}}/xml?noop=true”, 500) .when(header(“file.extension”).isEqualTo(“pdf”)) .pollEnrich(“file:///{{application.fileStorage.basePath}}/pdf?noop=true”, 500) .end() .convertBodyTo(File.class) .bean(responseProvider, “getResponse(${body}, 200)”); 此配置的问题是响应仅为第二个(为什么?)请求具有非空主体,没有超时设置服务在第二个请求上使用调试消息进入永久循环 DEBUG oaccfFileConsumer – Took 0.000 seconds to poll \xml Apace Camel版本是2.10.4 任何帮助,将不胜感激 UPD1 : Content Enricher页面上有警告,说’pollEnrich不访问当前Exchange中的任何数据’。 但是如果我将fileName=${body}到文件URL,则没有任何变化 UPD2 : […]

Camel – 将特定参数从路由传递到genericsbean方法

假设我有一条看起来像这样的Camel路线: from(“direct:myRoute”) .setHeader(“someHeader”, simple(“some header value”)) .beanRef(“myBean”, “beanMethod”); 我有一个我cannot change的bean,看起来像这样: public class MyBean { public void beanMethod(String headerExpected) { // do something with the value here. } } 基本上,我想将myRoute中someHeader的值传递给MyBean中的 beanMethod 。 知道beanMethod可以接受一个String ,我如何从路由中传递标题someHeader的值,以便在beanMethod中接受它作为String?