Spring Cloud AWS — SQS IGNORE QueueNotFoundStrategy
+
+ Spring Cloud AWS 3.x의 SQS 컨테이너에 IGNORE QueueNotFoundStrategy를 추가해, 큐가 없을 때 listener를 조용히 skip하고 application context 부팅을 차단하지 않도록 복원했습니다. spring-cloud-starter-aws-messaging (2.x) 의 기본 동작이었으나 3.x로 넘어오면서 사라져 다수의 사용자가 v2→v3 migration pain으로 보고한 항목입니다.
+
+
+
+
+
+
+
문제 — GH-1143
+
+ 3.x의 기존 두 전략은 FAIL (큐 없으면 throw, application startup 차단)과 CREATE (큐 없으면 CreateQueue 호출, sqs:CreateQueue IAM 필요 + 외부 관리 큐 설정과 충돌 가능). 둘 다 안 맞는 케이스가 흔함 — optional feature queue, multi-region rollout에서 일부 region에만 queue가 만들어진 상태, deployment마다 queue 존재 여부가 다른 케이스. 이 때 listener는 그냥 skip하고 앱은 정상 부팅돼야 함. 2.x의 spring-cloud-starter-aws-messaging는 이게 기본 동작이었음.
+
+
+
수정 — typed signal 도입
+
+ 메인테이너(@tomazfernandes)가 명시한 우려: "graciously handle the error thrown by the QueueAttributesResolver and interrupting container startup". 해결은 새 exception 타입을 신호로 사용해 source가 distinguish할 수 있게 하는 방향:
+
+
+
새 QueueNotFoundException 클래스 (QueueAttributesResolvingException의 subtype) 도입. 기존 catch 사이트는 parent 타입으로 그대로 잡힘.
+
QueueAttributesResolver.handleException: QueueDoesNotExistException + IGNORE일 때만 새 exception으로 failed future. CREATE / FAIL 경로 unchanged.
+
QueueAttributesResolver.wrapException: 새 exception만 unwrap 통과 (generic 재포장 방지).
+
AbstractSqsMessageSource.doStart: CompletionException cause가 새 exception이면 skipped 플래그 + warning + early return.
+
AbstractSqsMessageSource.doPollForMessages: skipped면 empty future 즉시 반환.
+
+
+
회귀 테스트
+
+ QueueAttributesResolverIntegrationTests#shouldIgnoreQueueWhenStrategyIsIgnore 추가. LocalStack에 존재하지 않는 큐 + IGNORE 전략 → QueueNotFoundException (cause = QueueDoesNotExistException) surface 검증. 같은 클래스의 FAIL/CREATE 기존 6개 테스트 모두 그대로 통과 — RetryableTopic 시나리오 무영향.
+
PR #1640 — GH-1143: Add IGNORE QueueNotFoundStrategy option for SQS
+
+ Spring Cloud AWS 3.x의 QueueNotFoundStrategy에 세 번째 옵션 IGNORE를 추가. SQS 큐가 startup 시점에 없을 때 warning 로그 + listener container의 source를 조용히 skip해 application context 부팅을 막지 않음. 2.x spring-cloud-starter-aws-messaging의 기본 동작을 3.x에 복원하는 패치. 4명 이상이 v2→v3 migration pain으로 보고한 이슈 #1143, 메인테이너 직접 "PRs welcome" 표명.
+
+ Spring Cloud AWS 3.x의 QueueNotFoundStrategy는 두 가지 — FAIL (큐 없으면 throw, application startup 차단) 또는 CREATE (큐 없으면 CreateQueue 호출, sqs:CreateQueue IAM 필요 + 외부 관리 큐 설정과 충돌 가능). 둘 다 안 맞는 사용 케이스가 있음 — 예: optional feature queue, multi-region rollout에서 큐가 아직 안 만들어진 상태, deployment마다 queue 존재 여부가 다른 경우. 이런 경우 listener는 그냥 skip하고 앱은 정상 부팅돼야 함. 2.x의 spring-cloud-starter-aws-messaging는 이게 기본 동작이었는데 3.x에서 사라지면서 migration pain이 생김 (이슈에 v2→v3 사용자 4명+ 보고).
+
+
+
설계 — typed signal로 분리
+
+ 메인테이너 (@tomazfernandes) 의 우려: "graciously handle the error thrown by the QueueAttributesResolver and interrupting container startup". 핵심은 IGNORE 신호를 generic resolver 에러와 어떻게 분리해서 source가 catch할 수 있게 만드느냐. 답은 dedicated exception 타입:
+
+
+
새 클래스 QueueNotFoundException — QueueAttributesResolvingException의 subtype. 기존 catch 사이트는 그대로 동작 (parent 타입으로 잡힘), source는 subtype으로 distinguish 가능.
QueueAttributesResolver.wrapException: QueueNotFoundException만 unwrap 통과 (generic 재포장 방지). 다른 모든 exception은 종전 그대로 QueueAttributesResolvingException으로 wrap.
+
AbstractSqsMessageSource.doStart: CompletionException cause가 QueueNotFoundException이면 skipped 플래그 set + warning + early return (queueAttributes/queueUrl 안 set, conversion context 안 설정).
+
AbstractSqsMessageSource.doPollForMessages: skipped면 즉시 CompletableFuture.completedFuture(emptyList()) — polling loop은 source 라이프타임 동안 no-op.
+
+
+
FAIL / CREATE / RetryableTopic은 손 안 댐
+
+ 새 IGNORE constant만 새 branch를 탐. wrapException의 QueueNotFoundException 분기는 IGNORE에서만 생성되므로 다른 strategy / 다른 exception 경로에서는 종전과 동일한 QueueAttributesResolvingException이 떨어짐. 기존 회귀 테스트 6개 모두 동일 exception 타입을 그대로 받음을 LocalStack 통합 테스트로 확인.
+
+
+
회귀 테스트
+
+ QueueAttributesResolverIntegrationTests#shouldIgnoreQueueWhenStrategyIsIgnore 추가. 기존 #shouldNotCreateQueue 패턴 그대로 사용, LocalStack에 존재하지 않는 큐에 IGNORE 전략을 적용했을 때 QueueNotFoundException (cause = QueueDoesNotExistException)이 surface됨을 검증. 같은 클래스의 7개 테스트(FAIL/CREATE 케이스 포함) 모두 통과.
+
+
+
속성 바인딩
+
+ SqsProperties에서 QueueNotFoundStrategy enum을 직접 노출하고 있어 코드 변경 없이 spring.cloud.aws.sqs.queue-not-found-strategy=IGNORE로 바로 설정 가능. sqs.adoc 표 항목에 IGNORE 동작 설명 한 줄 추가.
+
+ Spring Cloud AWS 3.x SQS 컨테이너에 IGNORE QueueNotFoundStrategy를 추가해, 큐가 없을 때 listener를 조용히 skip하고 application context 부팅을 차단하지 않도록 복원했습니다. 2.x spring-cloud-starter-aws-messaging의 기본 동작을 typed exception을 도입해 FAIL / CREATE / RetryableTopic 경로를 손대지 않고 분리해 적용했습니다.
+