103.21. 동일한 파일을 두 번 이상 읽지 않도록 (idempotent consumer)
Camel은 이미 처리된 파일을 건너뛰도록 구성 요소 내에서 직접 Idempotent Consumer를 지원합니다. 멱등 =true 옵션을 설정하여 이 기능 을 활성화할 수 있습니다.
from("file://inbox?idempotent=true").to("...");Camel은 절대 파일 이름을 멱등 키로 사용하여 중복 파일을 탐지합니다. Camel 2.11 이후부터는 idempotentKey 옵션의 표현식을 사용하여 이 키를 사용자 지정할 수 있습니다. 예를 들어 이름 및 파일 크기를 모두 키로 사용하려면
<route>
<from uri="file://inbox?idempotent=true&idempotentKey=${file:name}-${file:size}"/>
<to uri="bean:processInbox"/>
</route>
기본적으로 Camel은 사용 중인 파일을 추적하는 데 in 메모리 기반 저장소를 사용하므로 최근에 사용한 캐시가 최대 1000개 항목을 보유하는 데 사용됩니다. # login in the value를 사용하여 해당 저장소 의 고유 구현을 플러그인하여 해당 값을 사용하여 지정된 id 가 있는 레지스트리의 빈을 참조하는 것을 나타낼 수 있습니다.
<!-- define our store as a plain spring bean --> <bean id="myStore" class="com.mycompany.MyIdempotentStore"/> <route> <from uri="file://inbox?idempotent=true&idempotentRepository=#myStore"/> <to uri="bean:processInbox"/> </route>
Camel은 이전에 사용되었기 때문에 파일을 건너뛰는 경우 DEBUG 수준에서 로깅합니다.
DEBUG FileConsumer is idempotent and the file has been consumed before. Will skip this file: target\idempotent\report.txt