simple AWS SQS client for Scala.
This library, has been inspired by com.kifi.franz. I like franz, but there are only a few of the configurations in order to create the AWS client. I wanted a more customizable interfaces.
supports Scala 2.11.x, 2.12.x
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.yoskhdia" %% "sqscala" % <<check the latest version from jitpack.>>
put application.conf in your classpath(resources).
# endpoint-url or region
# If you want to connect to localhost, example 'endpoint-url="http://localhost:9324"'
# endpoint-url = null
region = "us-west-2"
# max-retry = 3
# max-connections = 50
# connection-timeout-ms = 50000 # millis
# socket-timeout-ms = 50000 # millis
then your code, like
import com.github.yoskhdia.sqscala._
val client = ConfiguredSqsClient()
of course, you can wrap with container(e.g. aws.sqs { ... }
), then use ConfiguredSqsClient("aws.sqs")
.
You can use SqsClient with credential provider and regions. In many cases, it is easy that you should use regions pattern. Of course, you can instantiate AWS client directly, and set SqsClient object to first argument.
import com.amazonaws.regions.Regions
import com.github.yoskhdia.sqscala._
val client = SqsClient()
// or
val client = SqsClient(regions = Regions.US_WEST_2)
// or
val client = SqsClient(credentialProvider = new YourCustomCredentialProvider())
Get a queue object from SqsClient.
val queue = client.queue(QueueName("foo"))
// or
val queue = client.queue(QueueName("foo"), createIfNotExists = true)
SqsQueue requires MessageSerializer used to serialize/deserialize the SQS message body. (Message Body <=> Any Type) By default, sqscala has only a StringSerializer(Message Body <=> String). You can switch it on implicit parameter.
import com.github.yoskhdia.sqscala.Implicits.stringSerializer
// or
implicit val serializer = YourOriginalSerializer
then you can use queue, like
// send message to SQS
queue.send("hello, sqs.").onComplete {
// ...
}
// receive message from SQS
queue.receive().onComplete {
case Success(message) => // ...
case Failure(exception) => // ...
}
// delete message from SQS
queue.receive().onSuccess {
case Some(message) =>
// ...
queue.delete(message.receiptHandle).onComplete {
// ...
}
}
- Directly instantiate the SQS queue objects from the URL.
import com.amazonaws.regions.Regions
import com.github.yoskhdia.sqscala._
val client = SqsClient()
val queue = client.unsafe.queue(QueueName("foo"), "https://localhost:9324")
- support batch request.
- support queue attributes.
- support JSON serialization.
- support stream access.