标签: apache-camel

Apache Camel ftp使用者一次又一次地加载相同的文件

我有以下弹簧配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring 
       http://camel.apache.org/schema/spring/camel-spring.xsd">

    <bean id="downloadLogger" class="com.thomsonreuters.oa.sdi.camel.DownloadLogger" />

    <bean id="fileFilter" class="com.thomsonreuters.oa.sdi.camel.IgnoreReadyFilesFilter" />

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="ftp://url_to_ftp?password=*******&amp;noop=true&amp;stepwise=false&amp;binary=true&amp;consumer.delay=10s&amp;recursive=true&amp;filter=#fileFilter" />
            <process ref="downloadLogger" />
            <to uri="file:data/outbox" />
        </route>
    </camelContext>

</beans>
Run Code Online (Sandbox Code Playgroud)

在ftp方面,我有3个文件夹,包含我要下载的文件.我想实现以下场景:

  1. 在ftp上,第一个数据拉消费者将固定数量的文件(对于isntance 5)加载到目标文件夹
  2. 在第二次尝试加载文件时,ftp状态仍然相同(5个文件)和驼峰ftp消费者什么都不做(除了检查新文件)
  3. 要ftp到达新的2个文件,在这个数据拉消费者只下载这两个新文件

目前,当我运行dataload进程时,我的当前解决方案每次下载所有文件,我如何管理有关下载文件的信息以防止重复下载(我的意思是已经从ftp复制了文件),我可以编写自己的过滤器,它将过滤掉已经下载的文件,但我相信应该有内置的功能,这将给我控制这个(也许是idempotentRepository,实际上我不确定)...

java ftp apache-camel

6
推荐指数
1
解决办法
1万
查看次数

骆驼阅读文件内容

有没有办法(api函数)在没有编写转换器或任何java代码的情况下读取camel中文件的整个内容(或逐行)?

谢谢

java file apache-camel

6
推荐指数
1
解决办法
9406
查看次数

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)");
Run Code Online (Sandbox Code Playgroud)

此配置的问题是响应仅为第二个(为什么?)请求具有非空主体,没有超时设置服务在第二个请求上使用调试消息进入永久循环

DEBUG o.a.c.c.f.FileConsumer - Took 0.000 seconds to poll <base path>\xml
Run Code Online (Sandbox Code Playgroud)

Apace Camel版本是2.10.4

任何帮助,将不胜感激

UPD1:Content Enricher页面
上有警告,说'pollEnrich不访问当前Exchange的任何数据'.但是,如果添加到文件URL,则没有任何变化fileName=${body}

UPD2:
看起来pollEnrich不支持fileNameURL(链接)中指定的动态.目前的路线:

from("direct:fetchFile")
    .process(fetchFileProcessor) // set file.id & file.extension
    .bean(fileService, "fetchFile(${header.file.id}, ${header.file.extension})") // set body to filename
    .choice()
        .when(header("file.extension").isEqualTo("xml"))
            .pollEnrich("file:///{{application.fileStorage.basePath}}/xml?fileName=${body}&noop=true", 500)
            .setHeader("asset.type", simple(MediaType.APPLICATION_XML)) …
Run Code Online (Sandbox Code Playgroud)

java rest cxf apache-camel java-ee

6
推荐指数
1
解决办法
1万
查看次数

使用Apache Camel解压缩文件?

如何使用Apache Camel从zip文件中提取文件(一个或多个)?可能吗?

我正在尝试这个

from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
  .split(new ZipSplitter())
    .streaming().convertBodyTo(String.class)      
  .to("file:/home/myinputzip")
.end();
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序时,文件是从zip中提取的,但是camel会抛出异常并将文件移动到错误文件夹:

错误:org.apache.camel.processor.DefaultErrorHandler - (ExchangeId上的MessageId:ID-ubuntu-35217-1377806407437-0-5:ID-ubuntu-35217-1377806407437-0-7)的传递失败.交付尝试后用尽:1捕获:org.apache.camel.component.file.GenericFileOperationFailedException:无法将null body写入文件:/home/myinputzip/aVIII_crrpfp201304.cap org.apache.camel.component.file.GenericFileOperationFailedException:无法写入null body to file:/home/myinputzip/aVIII_crrpfp201304.cap org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:194)at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer. java:257)org.apache中的org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:159)atg.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80)位于org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)的.camel.util.AsyncProcessorConverterHelper $ ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)org.apache.camel.processor.SendProcessor $ 2.doInAsyncProducer( SendProcessor.java:122)org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)

谁能帮我?

file unzip apache-camel

6
推荐指数
1
解决办法
6524
查看次数

在Camel v2.16.0中替换Deprecated beanRef()

我们正在从Camel v2.13升级到v2.16,并发现beanRef()已被标记为已弃用.Apache Camel推荐的替代品/替代品是什么?我无法在Camel v2.16.0文档站点上找到任何有用的东西.甚至还没有更新的例子.

beanRef()是Camel的Java DSL Bean语言中的语法.

java apache-camel

6
推荐指数
1
解决办法
2551
查看次数

如何在Camel Processor中使用属性占位符

我正在用驼峰编写一些路由,我想使用处理器进行一些转换.我有一个属性文件,它工作正常.

    from(URI_LOG)
    .routeId("{{PREFIX_LOG}}.prepareForMQ") 
    .log("Mail to: {{MAIL}}") //The value is read from a property file
    .process(new ProcessorPrepareMail())
    .log("${body}");
Run Code Online (Sandbox Code Playgroud)

现在......我想在处理器内读取{{MAIL}}的值,但我不知道如何.

我试过这些东西:

public class ProcessorPrepareMail implements Processor
{

    @Override
    public void process(Exchange exchange) throws Exception
    {
        //Plan A: Does not work.... I get an empty String
        String mail = exchange.getProperty("MAIL", String.class);

        //Plan B: Does not work.... I get the String "{{MAIL}}"
        Language simple = exchange.getContext().resolveLanguage("simple");
        Expression expresion = simple.createExpression("{{MAIL}}");
        String valor = expresion.evaluate(exchange, String.class);

        //Plan C: Does not work. It activates the default …
Run Code Online (Sandbox Code Playgroud)

java integration apache-camel

6
推荐指数
1
解决办法
3315
查看次数

使用Apache Camel发送POST请求

我能够使用Apache Camel将GET请求发送到REST服务,现在我正尝试使用Apache Camel发送具有JSON正文的POST请求。我无法弄清楚如何添加JSON正文和发送请求。如何添加JSON正文,发送请求并获取响应代码?

java rest post apache-camel camel-http

6
推荐指数
2
解决办法
1万
查看次数

使用@SpringBootTest进行Spring Boot和Camel测试

我有spring boot app,有1.5.8版本的spring boot。 camel 2.20.1

简单路线:

@Component
public class MyRoute extends RouteBuilder {

  public static final String IN = "file://in";

  public static final String OUT = "file://out";

  @Override
  public void configure() throws Exception {
    from(IN).routeId("myId").to(OUT);
  }
}
Run Code Online (Sandbox Code Playgroud)

Und简单测试:

//@SpringBootTest
public class MyRouteTest extends CamelTestSupport {


      @Produce(uri = MyRoute.IN)
      private ProducerTemplate producerTemplate;

      @EndpointInject(uri = "mock:file:out")
      private MockEndpoint mockEndpointOut;

      @Override
      public String isMockEndpoints() {
        return "*";
      }

      @Test
      public void simpleTest() throws Exception {
        mockEndpointOut.expectedMessageCount(1);
        producerTemplate.sendBody("Test");
        mockEndpointOut.assertIsSatisfied();
      }

      @Override
      protected RoutesBuilder …
Run Code Online (Sandbox Code Playgroud)

java apache-camel spring-boot spring-boot-test spring-camel

6
推荐指数
2
解决办法
6803
查看次数

如何在 Camel 路由中调用 ${body} 上的 setter 方法?

我试图在 Java bean 的主体上设置一个属性,该属性构成通过 Camel 路由传输的消息。我尝试了各种方法,例如

    <route>
        ...
        ..
        <transform>
            <simple>${body.label} = ${property.label}</simple>
        </transform>
        ...
        ..
    </route>
Run Code Online (Sandbox Code Playgroud)

在这种特殊情况下,它${body}是一个带有setLabel(String label)方法的 Java bean,它${property.label}是通过其他方式在另一个路由中设置的。在这个例子中,结果不是想要的(我明白为什么),即在转换之后,消息的正文被替换为${body.label} = ${property.label}字符串。

我目前的解决方法是将转换器手动编码为 Spring bean 并在代码中设置 Java bean 的标签属性,但我想找出是否有更简单/更智能的方法来实现这一点,最好是在 XML DSL 中我用什么?

问候,奥拉

apache-camel

5
推荐指数
1
解决办法
6834
查看次数

xml中的apache骆驼过滤器。xml中传递参数给Bean

我是使用 activemq 和 Camel 的新手。

我有这些问题:

  1. 我有一个 bean 和 bean 方法,它们由过滤器调用。

    <filter>
       <method ref="MyBean" method="CheckReceivedFilesByParameters"/>
       <to uri="direct:b"/>
    </filter>
    
    Run Code Online (Sandbox Code Playgroud)

    方法 CheckReceivedFilesByParameters 返回布尔值。如果为真,则下一条路线成功启动。错误时如何调用路由(直接:b)。我想用 xml 来做到这一点。我试图在标签外调用方法,但没有运气。

    <to uri="bean:MyBean?method=CheckReceivedFilesByParameters"/>
    <filter>
       <simple>false</simple>
       <to uri="direct:b"/>
    </filter>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 如何通过 Exchange 消息正确地将参数传递给 MyBean 方法。什么是最佳实践?现在我通过创建标题来做,稍后在我的方法中我得到 headerValues。我的 xml 中的示例。

    <setHeader headerName="RouteId">
        <constant>Test1</constant>
    </setHeader>
    
    Run Code Online (Sandbox Code Playgroud)

    然后在 MyBean 方法值中获取标题。 String routeId = exchange.getIn().getHeader("RouteId", String.class);

    应该有一些更“优雅”的方式。就像传递参数一样。就像在 servlet 中一样?

    request.getParameter("par1")

提前致谢。

java xml spring activemq-classic apache-camel

5
推荐指数
1
解决办法
3020
查看次数