Skip to content

Commit

Permalink
Fail at startup if queues are not the same type for a container
Browse files Browse the repository at this point in the history
  • Loading branch information
internetstaff committed Jun 8, 2024
1 parent 4e9cd0e commit 12f25ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ public SqsMessageListenerContainer(SqsAsyncClient sqsAsyncClient) {

@Override
protected Collection<ContainerComponentFactory<T, SqsContainerOptions>> createDefaultComponentFactories() {
Assert.isTrue(allQueuesSameType(),
"SqsMessageListenerContainer must contain either all FIFO or all Standard queues.");
return Arrays.asList(new FifoSqsComponentFactory<>(), new StandardSqsComponentFactory<>());
}

private boolean allQueuesSameType() {
return getQueueNames().stream().allMatch(this::isFifoQueue)
|| getQueueNames().stream().noneMatch(this::isFifoQueue);
@Override
public void setQueueNames(Collection<String> queueNames) {
Assert.isTrue(
queueNames.stream().allMatch(this::isFifoQueue) || queueNames.stream().noneMatch(this::isFifoQueue),
"SqsMessageListenerContainer must contain either all FIFO or all Standard queues.");
super.setQueueNames(queueNames);
}

private boolean isFifoQueue(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,14 @@ void shouldNotThrowIfProperCustomExecutorAckResult() {
container.stop();
}

@Test
void shouldThrowIfMixedQueueTypes() {
SqsAsyncClient client = mock(SqsAsyncClient.class);
SqsMessageListenerContainer.Builder<Object> builder = SqsMessageListenerContainer.builder()
.sqsAsyncClient(client).queueNames("queue", "queue.fifo");

assertThatThrownBy(builder::build).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("must contain either all FIFO or all Standard queues");
}

}

0 comments on commit 12f25ed

Please sign in to comment.