简单的骆驼 ftp 路由超时
Simple camel ftp route timeout
我在测试中配置了一个简单的路由 class 见下文:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class TestClass extends CamelTestSupport {
String ftpSourceUri = "ftp://some.server.com:21?username=user&password=secret&fileName=test.csv";
@Test
public void testRouteConsumesTestFileFromFTPEndpoint() throws Exception{
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from(ftpSourceUri)
.multicast().to("mock:result","stream:out");
}
};
}
}
我已经通过 FileZilla 验证了身份验证详细信息和文件位置。
This is the trace snippet produced by camel when I execute the above
code:
[ main] DefaultCamelContext INFO
Apache Camel 2.14.0 (CamelContext: camel-1) is starting [
main] DefaultManagementStrategy INFO JMX is disabled [
main] DefaultTypeConverter INFO Loaded 192 type converters
[ main] DefaultCamelContext INFO
AllowUseOriginalMessage is enabled. If access to the original message
is not needed, then its recommended to turn this option off as it may
improve performance. [ main]
DefaultCamelContext INFO StreamCaching is not in use. If
using streams then its recommended to enable stream caching. See more
details at [ main] DefaultCamelContext
INFO Route: route1 started and consuming from: Endpoint['endpoint
url'] <-- I can't post more than 2 links apparently [
main] DefaultCamelContext INFO Total 1 routes, of which 1
is started. [ main] DefaultCamelContext
INFO Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.140
seconds [ main] MockEndpoint
INFO Asserting: Endpoint[mock://result] is satisfied
[tal-music-ftp.amazonmp3.com:21] FtpConsumer INFO
Connected and logged in to: ['endpoint url'] <-- I can't post more
than 2 links apparently [ main]
AmazonMP3SimpleFTPRouteTest INFO
******************************************************************************** [ main] AmazonMP3SimpleFTPRouteTest INFO
Testing done:
testRouteConsumesTestFileFromFTPEndpoint(com.test.camel.SimpleFTPRouteTest)
[ main] AmazonMP3SimpleFTPRouteTest INFO
Took: 10.010 seconds (10010 millis) [ main]
AmazonMP3SimpleFTPRouteTest INFO
******************************************************************************** [ main] DefaultCamelContext INFO
Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down [
main] DefaultShutdownStrategy INFO Starting to graceful
shutdown 1 routes (timeout 10 seconds) [el-1) thread #1 -
ShutdownTask] DefaultShutdownStrategy INFO Waiting as there
are still 1 inflight and pending exchanges to complete, timeout in 10
seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy
INFO Waiting as there are still 1 inflight and pending exchanges to
complete, timeout in 9 seconds. [el-1) thread #1 - ShutdownTask]
DefaultShutdownStrategy INFO Waiting as there are still 1
inflight and pending exchanges to complete, timeout in 8 seconds.
[el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO
Waiting as there are still 1 inflight and pending exchanges to
complete, timeout in 7 seconds. [el-1) thread #1 - ShutdownTask]
DefaultShutdownStrategy INFO Waiting as there are still 1
inflight and pending exchanges to complete, timeout in 6 seconds.
[el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO
Waiting as there are still 1 inflight and pending exchanges to
complete, timeout in 5 seconds. [el-1) thread #1 - ShutdownTask]
DefaultShutdownStrategy INFO Waiting as there are still 1
inflight and pending exchanges to complete, timeout in 4 seconds.
[el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO
Waiting as there are still 1 inflight and pending exchanges to
complete, timeout in 3 seconds. [el-1) thread #1 - ShutdownTask]
DefaultShutdownStrategy INFO Waiting as there are still 1
inflight and pending exchanges to complete, timeout in 2 seconds.
[el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO
Waiting as there are still 1 inflight and pending exchanges to
complete, timeout in 1 seconds. [ main]
DefaultShutdownStrategy WARN Timeout occurred. Forcing the
routes to be shutdown now. Some resources may still be running.
[el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy WARN
Interrupted while waiting during graceful shutdown, will force
shutdown now. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy
INFO Route: route1 shutdown complete, was consuming from:
Endpoint['endpoint url'] <-- I can't post more than 2 links apparently
[ main] DefaultShutdownStrategy INFO
Graceful shutdown of 1 routes completed in 52 seconds [
main] DefaultCamelContext INFO Apache Camel 2.14.0
(CamelContext: camel-1) uptime 1 minute [
main] DefaultCamelContext INFO Apache Camel 2.14.0
(CamelContext: camel-1) is shutdown in 52.486 seconds
我可以做什么来简单地下载文件?
默认情况下,MockEndpoint 将在单元测试 10 秒后超时。因此您需要为 FTP 设置更长的等待时间来下载和处理文件。
你可以传入一个超时值,例如
assertMockEndpointsSatisfied(5, TimeUnit.MINUTES);
我在测试中配置了一个简单的路由 class 见下文:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class TestClass extends CamelTestSupport {
String ftpSourceUri = "ftp://some.server.com:21?username=user&password=secret&fileName=test.csv";
@Test
public void testRouteConsumesTestFileFromFTPEndpoint() throws Exception{
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from(ftpSourceUri)
.multicast().to("mock:result","stream:out");
}
};
}
}
我已经通过 FileZilla 验证了身份验证详细信息和文件位置。
This is the trace snippet produced by camel when I execute the above code:
[ main] DefaultCamelContext INFO Apache Camel 2.14.0 (CamelContext: camel-1) is starting [
main] DefaultManagementStrategy INFO JMX is disabled [
main] DefaultTypeConverter INFO Loaded 192 type converters [ main] DefaultCamelContext INFO AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. [ main] DefaultCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at [ main] DefaultCamelContext
INFO Route: route1 started and consuming from: Endpoint['endpoint url'] <-- I can't post more than 2 links apparently [
main] DefaultCamelContext INFO Total 1 routes, of which 1 is started. [ main] DefaultCamelContext
INFO Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.140 seconds [ main] MockEndpoint
INFO Asserting: Endpoint[mock://result] is satisfied [tal-music-ftp.amazonmp3.com:21] FtpConsumer INFO Connected and logged in to: ['endpoint url'] <-- I can't post more than 2 links apparently [ main] AmazonMP3SimpleFTPRouteTest INFO ******************************************************************************** [ main] AmazonMP3SimpleFTPRouteTest INFO Testing done: testRouteConsumesTestFileFromFTPEndpoint(com.test.camel.SimpleFTPRouteTest) [ main] AmazonMP3SimpleFTPRouteTest INFO Took: 10.010 seconds (10010 millis) [ main] AmazonMP3SimpleFTPRouteTest INFO ******************************************************************************** [ main] DefaultCamelContext INFO Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down [
main] DefaultShutdownStrategy INFO Starting to graceful shutdown 1 routes (timeout 10 seconds) [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 10 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy
INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 9 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 8 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 7 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 6 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 5 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 4 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 3 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 2 seconds. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 1 seconds. [ main] DefaultShutdownStrategy WARN Timeout occurred. Forcing the routes to be shutdown now. Some resources may still be running. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy WARN Interrupted while waiting during graceful shutdown, will force shutdown now. [el-1) thread #1 - ShutdownTask] DefaultShutdownStrategy INFO Route: route1 shutdown complete, was consuming from: Endpoint['endpoint url'] <-- I can't post more than 2 links apparently [ main] DefaultShutdownStrategy INFO Graceful shutdown of 1 routes completed in 52 seconds [
main] DefaultCamelContext INFO Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute [
main] DefaultCamelContext INFO Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 52.486 seconds
我可以做什么来简单地下载文件?
默认情况下,MockEndpoint 将在单元测试 10 秒后超时。因此您需要为 FTP 设置更长的等待时间来下载和处理文件。
你可以传入一个超时值,例如
assertMockEndpointsSatisfied(5, TimeUnit.MINUTES);