Skip to main content

Making a Client

To start off with SQS, we want to make an instance of SQSQueue to represent all the things we can do to a queue.

We'll start off by importing cats-effect, since this example will use cats.effect.IO.

We'll also be using the Blaze client from http4s, so we'll want the builder for that.

Then we want all of the common classes in Fawn, and all of the sqs classes.

import cats.effect._
import org.http4s.client.blaze.BlazeClientBuilder
import com.meltwater.fawn.common._
import com.meltwater.fawn.sqs._

import scala.concurrent.ExecutionContext

Next we'll want to create all of our settings, these would usually come from a config file or command line parser, but we'll instantiate them directly here.

val credentials = AWSCredentials("KEYID", "SECRET")
// credentials: AWSCredentials = AWSCredentials(
// accessKeyId = "KEYID",
// secretAccessKey = "SECRET"
// )
val region = AWSRegion.`eu-west-1`
// region: AWSRegion = AWSRegion(value = "eu-west-1")
val accountId = 123456L
// accountId: Long = 123456L
val queueName = "my-queue"
// queueName: String = "my-queue"

We can then create a Resource for our http4s client and map it into an SQSQueue

val queueResource: Resource[IO, SQSQueue[IO]] = 
BlazeClientBuilder[IO](ExecutionContext.global).resource.map { client =>
SQSQueue[IO](client, credentials, region, accountId, queueName)
}

You would then use it or tie it in with your program's other Resources:

queueResource.use { queue =>
queue.sendMessage("hello world")
}