com.katanox.tabour.configuration.sqs.Configuration.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
A Kotlin library to consume and produce SQS messages
package com.katanox.tabour.configuration.sqs
import com.katanox.tabour.configuration.core.config
import com.katanox.tabour.consumption.ConsumptionError
import com.katanox.tabour.sqs.SqsRegistry
import com.katanox.tabour.sqs.config.SqsConsumer
import com.katanox.tabour.sqs.config.SqsConsumerConfiguration
import com.katanox.tabour.sqs.production.ProductionError
import com.katanox.tabour.sqs.production.SqsProducer
import com.katanox.tabour.sqs.production.SqsProducerConfiguration
import java.net.URL
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.sqs.model.Message
fun sqsRegistryConfiguration(
key: T,
credentialsProvider: AwsCredentialsProvider,
region: Region,
init: SqsRegistry.Configuration.() -> Unit
): SqsRegistry.Configuration =
config(SqsRegistry.Configuration(key, credentialsProvider, region), init)
fun sqsRegistryConfiguration(
key: T,
credentialsProvider: AwsCredentialsProvider,
region: Region
): SqsRegistry.Configuration = SqsRegistry.Configuration(key, credentialsProvider, region)
/** Creates a new [SqsRegistry] */
fun sqsRegistry(config: SqsRegistry.Configuration): SqsRegistry = SqsRegistry(config)
/**
* Creates a new [SqsConsumer] which can be registered to [SqsRegistry]. The [url] is the url of the
* queue and uses [init] to configure the consumers properties
*/
fun sqsConsumer(
url: URL,
key: T,
onSuccess: suspend (Message) -> Boolean,
onError: suspend (ConsumptionError) -> Unit,
init: SqsConsumer.() -> Unit
): SqsConsumer = config(SqsConsumer(url, key, onSuccess, onError), init)
/**
* Creates a new [SqsConsumer] which can be registered to [SqsRegistry]. The [url] is the url of the
* queue
*/
fun sqsConsumer(
url: URL,
key: T,
onSuccess: suspend (Message) -> Boolean,
onError: suspend (ConsumptionError) -> Unit
): SqsConsumer = SqsConsumer(url, key, onSuccess, onError)
/**
* Creates a new [SqsProducer] which can be registered to [SqsRegistry]. The [url] is the url of the
* queue
*/
fun sqsProducer(
url: URL,
key: T,
onError: suspend (ProductionError) -> Unit,
init: SqsProducer.() -> Unit
): SqsProducer = config(SqsProducer(key, url, onError), init)
fun sqsProducer(url: URL, key: T, onError: (ProductionError) -> Unit): SqsProducer =
SqsProducer(key, url, onError)
/** Creates a new [SqsConsumerConfiguration] which can be used to configure a [SqsConsumer] */
fun sqsConsumerConfiguration(init: SqsConsumerConfiguration.() -> Unit): SqsConsumerConfiguration =
config(SqsConsumerConfiguration(), init)
/** Creates a new [SqsProducerConfiguration] which can be used to configure a [SqsProducer] */
fun sqsProducerConfiguration(init: SqsProducerConfiguration.() -> Unit): SqsProducerConfiguration =
config(SqsProducerConfiguration(), init)