Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ack/nack idempotent on an empty batch #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,47 @@ private class SQSMessageBatch[F[_], T](
override def messages: Chunk[Message[F, T]] = payload

override def ackAll: F[Unit] =
F.unlessA(payload.isEmpty) {
F.fromCompletableFuture {
F.delay {
client.deleteMessageBatch(
DeleteMessageBatchRequest
.builder()
.queueUrl(queueUrl)
.entries(payload.map { m =>
DeleteMessageBatchRequestEntry
.builder()
.receiptHandle(m.receiptHandle)
.id(m.messageId)
.build()
}.asJava)
.build()
)
}
}
}.void

override def nackAll: F[Unit] = F.unlessA(payload.isEmpty) {
F.fromCompletableFuture {
F.delay {
client.deleteMessageBatch(
DeleteMessageBatchRequest
.builder()
.queueUrl(queueUrl)
.entries(payload.map { m =>
DeleteMessageBatchRequestEntry
val req = ChangeMessageVisibilityBatchRequest
.builder()
.queueUrl(queueUrl)
.entries(
payload.map { m =>
ChangeMessageVisibilityBatchRequestEntry
.builder()
.receiptHandle(m.receiptHandle)
.id(m.messageId)
.receiptHandle(m.receiptHandle)
.visibilityTimeout(0)
.build()
}.asJava)
.build()
}.asJava
)
.build()
client.changeMessageVisibilityBatch(
req
)
}
}.void

override def nackAll: F[Unit] = F.fromCompletableFuture {
F.delay {
val req = ChangeMessageVisibilityBatchRequest
.builder()
.queueUrl(queueUrl)
.entries(
payload.map { m =>
ChangeMessageVisibilityBatchRequestEntry
.builder()
.id(m.messageId)
.receiptHandle(m.receiptHandle)
.visibilityTimeout(0)
.build()
}.asJava
)
.build()
client.changeMessageVisibilityBatch(
req
)
}
}.void
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ trait QueueSubscriberSuite extends CatsEffectSuite { self: QueueClientSuite =>
}
}

withQueue.test("messageBatch noop ack/nack on empty batches") { queueName =>
val client = clientFixture()
client.subscribe(queueName).puller.use { puller =>
for {
msgBatch <- puller.pullMessageBatch(10, waitingTime)
_ = assertEquals(msgBatch.messages.size, 0)
_ <- msgBatch.nackAll
_ <- msgBatch.ackAll
_ <- assertIOBoolean(
puller.pullMessageBatch(10, waitingTime).map(_.messages.isEmpty)
)
} yield ()
}
}

withQueue.test("process respects the decision from the handler") { queueName =>
val client = clientFixture()
for {
Expand Down
Loading