繁体   English   中英

Apache Camel FTP 无法捕获远程 FTP 文件夹上的文件创建事件

[英]Apache Camel FTP can not catch file created events on remote FTP folder

我正在尝试使用 Apache Camel FTP 来使用被推送到 FTP 文件夹的文件。 用于骆驼上下文的 FTP 服务器的路由和连接正常,但是当文件被推送到 FTP 文件夹时,我无法处理文件创建事件。 这是我的代码和日志:首先是我的 pom.xml 的一部分,用于骆驼(我使用的是骆驼 3.0.1 版本):

<!-- Listen FTP folder -->
        <!-- https://mvnrepository.com/artifact/org.apache.camel.springboot/camel-spring-boot-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-core-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel.springboot/camel-ftp-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-ftp-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel.springboot/camel-jacksonxml-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-jacksonxml-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel.springboot/camel-jackson-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-jackson-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel.springboot/camel-rabbitmq-starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-rabbitmq-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>

RouteBuilder 初始化骆驼消费:

package xx.listener.route;

import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.springframework.stereotype.Component;

import xx.listener.common.model.ddXMLModel;

@Component
public class DataRouter extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        System.out.println("Initialize camel route...");
        JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
        jacksonDataFormat.setInclude("NON_NULL");
        jacksonDataFormat.setPrettyPrint(true);

        from("ftp://user@localhost:21/ftp/files?password=abc@123&move=.done&moveFailed=.error")
                .log("${body}")
                .unmarshal().jacksonxml(ddXMLModel.class)
                .marshal(jacksonDataFormat)
                .log("${body}")
                .to("rabbitmq://localhost:5672/test_camel?username=root&password=123456&queue=camel.queue&autoDelete=false").end();
    }
}

启动应用程序时的日志:

Initialize camel route...
[INFO ] 2020-12-22 14:21:24.522 [main] SpringBootRoutesCollector - Loading additional Camel XML routes from: classpath:camel/*.xml
[INFO ] 2020-12-22 14:21:24.522 [main] SpringBootRoutesCollector - Loading additional Camel XML rests from: classpath:camel-rest/*.xml
[INFO ] 2020-12-22 14:21:24.530 [main] SpringBootCamelContext - Apache Camel 3.0.1 (CamelContext: camel-1) is starting
[INFO ] 2020-12-22 14:21:24.531 [main] JmxManagementStrategy - JMX is enabled
[WARN ] 2020-12-22 14:21:24.747 [main] RabbitMQComponent - The old syntax rabbitmq://hostname:port/exchangeName is deprecated. You should configure the hostname on the component or ConnectionFactory
[INFO ] 2020-12-22 14:21:24.755 [main] SpringBootCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[WARN ] 2020-12-22 14:21:24.772 [main] JacksonDataFormat - The option autoDiscoverObjectMapper is set to false, Camel won't search in the registry
[INFO ] 2020-12-22 14:21:24.897 [main] SpringBootCamelContext - Route: route1 started and consuming from: ftp://user@localhost:21/ftp/files?move=.done&moveFailed=.error&password=xxxxxx
[INFO ] 2020-12-22 14:21:24.902 [main] SpringBootCamelContext - Total 1 routes, of which 1 are started
[INFO ] 2020-12-22 14:21:24.904 [main] SpringBootCamelContext - Apache Camel 3.0.1 (CamelContext: camel-1) started in 0.372 seconds
[INFO ] 2020-12-22 14:21:24.908 [main] ListenerApplication - Started ListenerApplication in 2.979 seconds (JVM running for 4.169)

我连接到我的 FTP 服务器,切换到文件目录并将示例 xml 文件推送到此文件夹,我的应用程序控制台中没有任何反应。 我没有更多的日志了。

我还尝试在应用程序主 class 中添加到骆驼上下文的路由。 但我得到了同样的结果。

CamelContext camelContext = new DefaultCamelContext();
        try {
            camelContext.addRoutes(new DataRouter());
            camelContext.start();
        }
        catch (Exception e){
            e.printStackTrace();
            camelContext.stop();
        }

我的代码有什么问题。 谢谢

只有 2 个想法,因为什么也没发生(没有读取文件,没有错误)

  • 用户是否有权查看文件?
  • [userHome]/ftp/files下的文件是什么?

第二点是因为 Camel FTP 路径总是相对的。 因此用户的home路径,即用户登录ftp后登陆的目录,是路径的起点。

最后:尝试将日志级别提高到 DEBUG

通过将passiveMode=true添加到ftp uri 以允许登录到ftp 服务器来解决此问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM