104.21. 동일한 파일을 두 번 이상 읽지 않도록 (idempotent 소비자)
Camel은 구성 요소 내에서 직접 Idempotent Consumer를 지원하므로 이미 처리된 파일을 건너뜁니다. 이 기능은 idempotent=true
옵션을 설정하여 활성화할 수 있습니다.
from("file://inbox?idempotent=true").to("...");
from("file://inbox?idempotent=true").to("...");
Camel은 절대 파일 이름을 idempotent 키로 사용하여 중복 파일을 감지합니다. Camel 2.11 이상에서 idempotentKey 옵션의 표현식을 사용하여 이 키를 사용자 지정할 수 있습니다. 예를 들어 이름과 파일 크기를 키로 사용하려면 다음을 수행합니다.
<route> <from uri="file://inbox?idempotent=true&idempotentKey=${file:name}-${file:size}"/> <to uri="bean:processInbox"/> </route>
<route>
<from uri="file://inbox?idempotent=true&idempotentKey=${file:name}-${file:size}"/>
<to uri="bean:processInbox"/>
</route>
기본적으로 Camel은 사용된 파일을 추적하기 위해 메모리 기반 저장소에 를 사용하며, 최근 사용된 캐시는 최대 1000개의 항목을 유지합니다. 값이 #
Sign을 사용하여 idempotentRepository
옵션을 사용하여 지정된 idempotentRepository가 있는 레지스트리의 8080을 참조하여 이 저장소를 직접 구현할 수 있습니다
.
Camel은 이전에 사용되었기 때문에 파일을 건너뛰는 경우 DEBUG
수준에서 로그됩니다.
DEBUG FileConsumer is idempotent and the file has been consumed before. Will skip this file: target\idempotent\report.txt
DEBUG FileConsumer is idempotent and the file has been consumed before. Will skip this file: target\idempotent\report.txt