Skip to content

Commit

Permalink
Allow building a SQSClient from SDK client
Browse files Browse the repository at this point in the history
As the implementation class is private, it can't be instantiated directly from user code. To still allow users to fully customize their SQS client, add a new smart constructor that just delegates, but has a clean signature.
  • Loading branch information
ybasket committed Sep 12, 2024
1 parent b9012fc commit a4fc01f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ object SQSClient {
}
.map(new SQSClient(_))

/**
* Creates an SQS client from a given instance of `SqsAsyncClient`.
*
* It is upon the caller to ensure closing of the underlying client once appropriate.
*/
def fromClient[F[_]](client: SqsAsyncClient)(implicit F: Async[F]): QueueClient[F] =
new SQSClient(client)

}
4 changes: 3 additions & 1 deletion docs/systems/sqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can create a client to service bus queues by using the [AWS SQS][sqs] module
libraryDependencies += "com.commercetools" %% "fs2-queues-aws-sqs" % "@VERSION@"
```

For instance you can create a managed client via a region and credentials as follows.
For instance, you can create a managed client via a region and credentials as follows.

```scala mdoc:compile-only
import cats.effect.IO
Expand All @@ -26,4 +26,6 @@ The client is managed, meaning that it uses a dedicated HTTP connection pool tha

If integrating with an existing code base where you already have an instance of `SdkAsyncHttpClient` that you would like to share, you can pass the optional `httpClient` parameter. If passed explicitly, the client is not closed when the resource is released, and it is up to the caller to manage it.

For full customization, you can supply your own instance of `SqsAsyncClient` by using `SQSClient.fromClient`. Note that this requires explicit management of the underlying client's lifecycle.

[sqs]: https://aws.amazon.com/sqs/

0 comments on commit a4fc01f

Please sign in to comment.