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 sqs config more configurable #838

Open
wants to merge 2 commits 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
13 changes: 2 additions & 11 deletions fs2-aws-sqs/src/main/scala/fs2/aws/sqs/SQS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,14 @@ object SQS {
type MsgBody = String

def create[F[_]: Async](
sqsConfig: SqsConfig,
sqsConfig: SqsConfig.Interface,
sqs: SqsAsyncClientOp[F]
): F[SQS[F]] =
new SQS[F] {
override def sqsStream: fs2.Stream[F, Message] =
fs2.Stream
.awakeEvery[F](sqsConfig.pollRate)
.evalMap(_ =>
sqs
.receiveMessage(
ReceiveMessageRequest
.builder()
.queueUrl(sqsConfig.queueUrl)
.maxNumberOfMessages(sqsConfig.fetchMessageCount)
.build()
)
)
.evalMap(_ => sqs.receiveMessage(sqsConfig.receiveMessageRequest))
.flatMap(response => fs2.Stream.emits(response.messages().asScala))

override def deleteMessagePipe: Pipe[F, Message, DeleteMessageResponse] =
Expand Down
31 changes: 27 additions & 4 deletions fs2-aws-sqs/src/main/scala/fs2/aws/sqs/SqsConfig.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
package sqs
import software.amazon.awssdk.services.sqs.model.*

import scala.concurrent.duration.*
import scala.jdk.CollectionConverters.*

case class SqsConfig(
queueUrl: String,
pollRate: FiniteDuration = 3.seconds,
fetchMessageCount: Int = 100
)
override val queueUrl: String,
override val pollRate: FiniteDuration = 3.seconds,
override val fetchMessageCount: Int = 100,
override val messageAttributeNames: Option[List[String]] = None
) extends SqsConfig.Interface

object SqsConfig {
trait Interface {
def queueUrl: String
def pollRate: FiniteDuration
def fetchMessageCount: Int
def messageAttributeNames: Option[List[String]]

def receiveMessageRequest: ReceiveMessageRequest = buildReceiveRequest.build()

protected def buildReceiveRequest: ReceiveMessageRequest.Builder = {
val blder = ReceiveMessageRequest
.builder()
.queueUrl(queueUrl)
.maxNumberOfMessages(fetchMessageCount)

messageAttributeNames.fold(blder)(names => blder.messageAttributeNames(names.asJava))
}
}
}