1
我測試我的應用程序,它將文件從ftp發送到我的電腦,我正在檢查不復制一個文件兩次。對於這個我使用IdempotentConsumer
。
我的問題是,我無法運行測試,因爲這個IdempotentConsumer
總是給我錯誤。
這怎麼解決?嘲笑IdempotentConsumer
類
@Component
public class Converter extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setTypeHints(String.valueOf("YES"));
from("ftp://[email protected]?" +
"noop=true&binary=true&consumer.delay=5s&include=.*xml")
.idempotentConsumer(header("CamelFileName"), FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat")))
.marshal(xmlJsonFormat).to("file://data").process(
new Processor() {
//System.out.println();
}
});
}
}
測試類
public class ConverterTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new Converter();
}
@Test
public void testAdvisedMockEndpoints() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:inputXML");
interceptSendToEndpoint("file://data")
.skipSendToOriginalEndpoint()
.to("mock:outXML");
}
});
context.start();
getMockEndpoint("mock:outXML").expectedMessageCount(1);
template.sendBody("direct:inputXML", "Test data");
assertMockEndpointsSatisfied();
}
}
,我發現了以下錯誤:
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: Test data]
Caused by: org.apache.camel.processor.idempotent.NoMessageIdException: No message ID could be found using expression: header(CamelFileName) on message exchange: Exchange[Message: Test data]
請分享您遇到的錯誤(詳細)。 –