Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用Citrus模拟SFTP和Kafka来集成测试基于xml的Spring Boot apache camel路由?_Spring Boot_Apache Camel_Integration Testing_Citrus Framework - Fatal编程技术网

Spring boot 使用Citrus模拟SFTP和Kafka来集成测试基于xml的Spring Boot apache camel路由?

Spring boot 使用Citrus模拟SFTP和Kafka来集成测试基于xml的Spring Boot apache camel路由?,spring-boot,apache-camel,integration-testing,citrus-framework,Spring Boot,Apache Camel,Integration Testing,Citrus Framework,我正在使用一个Spring引导应用程序,该应用程序是使用ApacheCamel-SpringXML路由编写的。几乎没有基于java的应用程序逻辑,它几乎完全是用xml编写的,并且基于各种骆驼路线 路由配置为通过属性文件连接到不同的环境和系统,使用属性,例如KAFKA_URL和KAFKA_PORT。在其中一个已实现的路由内,应用程序与以下设备连接,并使用/生成发送给它的消息: <to id="route_id_replaced_for_question" uri="kafka:{{env:K

我正在使用一个Spring引导应用程序,该应用程序是使用ApacheCamel-SpringXML路由编写的。几乎没有基于java的应用程序逻辑,它几乎完全是用xml编写的,并且基于各种骆驼路线

路由配置为通过属性文件连接到不同的环境和系统,使用属性,例如
KAFKA_URL和KAFKA_PORT
。在其中一个已实现的路由内,应用程序与以下设备连接,并使用/生成发送给它的消息:

<to id="route_id_replaced_for_question" uri="kafka:{{env:KAFKA_URL:{{KAFKA_URL}}}}:{{env:KAFKA_PORT:{{KAFKA_PORT}}}}?topic={{env:KAFKA_TOPIC:{{topic_to_connect_to}}}}&amp;kerberosRenewJitter=1&amp;kerberosRenewWindowFactor=1&amp;{{kafka.ssl.props}}&amp;{{kafka.encryption.props}}"/>
和一个具有以下功能的FTP服务器:

    @Bean
    public SftpServer sftpServer() {
        return CitrusEndpoints.sftp()
                .server()
                .port(2222)
                .autoStart(true)
                .user("username")
                .password("passwordtoconnectwith")
                .userHomePath("filedirectory/filestoreadfrom")
                .build();
    }
理想情况下,我的测试将连接到模拟sftp服务器,我将使用Citrus将文件推送到适当的目录,然后我的应用程序将读取、处理并发布到嵌入式kafka集群上的主题,并在测试中进行验证

我的印象是,我会在我的属性文件中将
KAFKA_-PORT
设置为9092,将
KAFKA_-URL
设置为localhost,将
FTP_-URL
设置为localhost,并将
FTP_-PORT
设置为2222(以及其他所需的属性),但这似乎无法将我连接到嵌入式集群或sftp服务器


让我的spring boot应用程序连接到这两个模拟实例并从那里运行其“业务逻辑处理”,我遗漏了什么

我解决了这个问题-这是因为使用了非常旧的卡夫卡版本(1.0.0或更旧版本),它缺少了一些在Citrus尝试构建新主题时调用的方法。如果有人在使用Citrus时遇到类似的问题,我建议首先评估您的服务的Kafka版本,并确定是否需要更新


对于sftp连接,服务器或客户端未自动连接,因此从未启动

这不仅仅是关于端口,您还需要确保使用正确的用户和密码连接到这些模拟服务器。另外,了解您如何运行测试以及错误消息/堆栈跟踪是什么样子也很好。在我的驼峰路由中连接时,我提供了与SftpServer相同的用户和密码(因此,在本例中,用户名和密码toconnectwith)。该应用程序通常正确地连接到我们实际的SFTP服务器,因此我不确定该代码是否有问题。现在我有一个非常简单的测试,它运行,启动Spring启动应用程序(作为测试的常规部分),然后打印“Hello,world!”并断言1==1。在检查日志时,stacktrace调用未能连接到这两个服务器,而通常会打印“以用户身份连接到sftp服务器”警告o.a.c.c.file.remote.SftpConsumer-错误自动创建目录:filedirectory/FileStoreReadFrom无法连接到sftp://username@本地主机:2222。此异常被忽略。org.apache.camel.component.file.GenericFileOperationFailedException:无法连接到sftp://username@localhost:2222由以下原因引起:com.jcraft.jsch.JSchException:java.net.ConnectException:Connection拒绝(Connection拒绝)
 @Bean
    public EmbeddedKafkaServer embeddedKafkaServer() {
        return new EmbeddedKafkaServerBuilder()
                .kafkaServerPort(9092)
                .topics("topic_to_connect_to")
                .build();
    }
    @Bean
    public SftpServer sftpServer() {
        return CitrusEndpoints.sftp()
                .server()
                .port(2222)
                .autoStart(true)
                .user("username")
                .password("passwordtoconnectwith")
                .userHomePath("filedirectory/filestoreadfrom")
                .build();
    }