如何让骆驼FTP按需仅获取一次

我是骆驼的新手。

我一直在尝试让骆驼按需通过FTP仅一次获取单个文件。我无法正常工作。这是我尝试过的。让我知道什么是最好的方法,我的代码有什么问题。

并在收到 停止路由。

 from("direct:myStart")

.routeId("routeA")

.pollEnrich("ftp:...disconnect=true&sendEmptyMessageWhenIdle=true")

.choice()

.when(body().isNull()).process(RouteStopper("routeA"))

.otherwise().to("validator:file.xsd")

.to("somewhere")

.end();

还有我的RouteStopper

public class RouteStopper implements Processor {

private String routeId;

private Thread stopper;

public RouteStopper(String routeId) {

this.routeId = routeId;

}

@Override

public void process(Exchange exchange) throws Exception {

if (stopper == null) {

stopper = new Thread() {

@Override

public void run() {

try {

exchange.getContext().stopRoute(routeId);

} catch (Exception e) {

}

}

};

}

stopper.start();

}

我第一次打电话时实际上效果很好 producerTemplate.sendBody("direct:myStart", null);

但是第二次我打电话给producerTemplate.sendBody("direct:myStart", null);我:

org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://myStart]. Exchange[Message: [Body is null]]

我想我要做的是不完全停止前进…所以我尝试了另一种方式…

public class FtpPollStrategy implements PollingConsumerPollStrategy {

@Override

public boolean begin(Consumer consumer, Endpoint endpoint) {

return true;

}

@Override

public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {

try {

consumer.stop();

}

catch (Exception e) {

e.printStackTrace();

}

}

@Override

public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception {

return false;

}

}

在我的路线上:

from("ftp:....disconnect=true&pollStrategy=#ftpPollStrategy")

我得到的是

java.lang.IllegalArgumentException: Could not find a suitable setter for property: pollStrategy as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.spi.PollingConsumerPollStrategy with value #ftpPollStrategy

3- (如下面的注释中所建议),则好像该路由从未停止轮询我的FTP 。我只给路线打过一次电话:

producerTemplate.sendBody("direct:myStart", null);

和路线

 from("direct:myStart")

.routeId("routeA")

.pollEnrich("ftp:...disconnect=true&sendEmptyMessageWhenIdle=true")

.to("validator:file.xsd")

.to("somewhere")

.end();

查看日志:

2015-08-05 08:55:28,942 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:152)

TelechargementMetadonneesRouteBuilder- Not connected/logged in, connecting to:

ftp://pierre@localhost:21 2015-08-05 08:55:28,943 INFO [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:156)

TelechargementMetadonneesRouteBuilder- Connected and logged in to:

ftp://pierre@localhost:21 2015-08-05 08:55:28,945 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.GenericFileConsumer:130)

TelechargementMetadonneesRouteBuilder- Took 0.002 seconds to poll: 2015-08-05

08:55:28,945 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:121)

TelechargementMetadonneesRouteBuilder- Disconnecting from:

ftp://pierre@localhost:21 2015-08-05 08:55:29,446 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:152)

TelechargementMetadonneesRouteBuilder- Not connected/logged in, connecting to:

ftp://pierre@localhost:21 2015-08-05 08:55:29,447 INFO [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:156)

TelechargementMetadonneesRouteBuilder- Connected and logged in to:

ftp://pierre@localhost:21 2015-08-05 08:55:29,449 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.GenericFileConsumer:130)

TelechargementMetadonneesRouteBuilder- Took 0.002 seconds to poll: 2015-08-05

08:55:29,449 DEBUG [correlation-

ids:faad163b-f68e-4e91-b5fd-e5e2f86d42bd,user:] [(camelContext)-1]

(org.apache.camel.component.file.remote.RemoteFileConsumer:121)

TelechargementMetadonneesRouteBuilder- Disconnecting from:

ftp://pierre@localhost:21

任何帮助将不胜感激。

回答:

因此,我发现的解决方案是使用场景1,但请停止并重新启动路由。

exchange.getContext().stopRoute(routeId);

exchange.getContext().startRoute(routeId);

以上是 如何让骆驼FTP按需仅获取一次 的全部内容, 来源链接: utcz.com/qa/405252.html

回到顶部