### Install and Configure Rate Limiting Plugin Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-rate-limiting/index.md Demonstrates how to install and configure the RateLimiting plugin within Ktor routing. It shows basic setup for a token bucket strategy, whitelisting, blacklisting, and a custom response handler for exceeded limits. ```kotlin routing { route("limited-route") { install(RateLimiting) { rateLimiter { type = TokenBucket::class rate = 1.seconds capacity = 100 } whiteListedHosts = setOf("trusted-host.com") blackListedAgents = setOf("malicious-agent") rateLimitExceededHandler = { rateLimiterResponse -> ... respond(HttpStatusCode.TooManyRequests, rateLimiterResponse.message) } } get { call.respondText("Welcome to our limited route!") } } } ``` -------------------------------- ### Configure Kafka Plugin from File Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-kafka/index.md Install the Kafka plugin using configurations from an application file (e.g., HOCON). This method simplifies setup by externalizing Kafka settings. You can specify a custom configuration path if needed. ```kotlin install(KafkaFromFileConfig.Kafka) { consumerConfig { consumerRecordHandler("my-topic") { record -> myService.save(record) } } registerSchemas { MyRecord::class at named("my-topic") // <-- Will register schema upon startup } } ``` ```kotlin install(KafkaFromFileConfig.Kafka("ktor.my.kafka")) { ... } ``` ```hocon ktor { kafka { schema.registry.url = ["SCHEMA_REGISTRY_URL"] common { "bootstrap.servers" = ["BOOTSTRAP_SERVERS"] # Additional configuration } admin { ##Additional configuration } consumer { "group.id" = "my-group-id" # Additional configuration } producer { "client.id" = "my-client-id" # Additional configuration } topics = [ { name = my-topic partitions = 1 replicas = 1 configs { "message.timestamp.type" = CreateTime # Additional configuration } } ] } } ``` -------------------------------- ### Kafka Plugin Configuration Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-kafka.md Example of how to install and configure the Kafka plugin in a Ktor application. This includes setting up schema registry URLs, defining topics with partitions and replicas, common bootstrap servers, and configuring admin, producer, and consumer clients. It also demonstrates how to set up a consumer record handler for a specific topic. ```APIDOC ## Kafka Plugin Configuration ### Description This section shows how to install and configure the Kafka plugin within your Ktor application. It covers various configuration options for Kafka clients, including schema registry, topic definitions, common settings, admin client, producer, and consumer configurations. A key feature demonstrated is the ability to define handlers for incoming Kafka records. ### Usage ```kotlin install(Kafka) { schemaRegistryUrl = listOf(super.schemaRegistryUrl) topic(it) { partitions = 1 replicas = 1 configs { messageTimestampType = CreateTime } } common { bootstrapServers = listOf("my-kafka") } admin { } // will create an admin producer { clientId = "my-client-id" } // will create a producer consumer { groupId = "my-group-id" } // will create a consumer consumerConfig { consumerRecordHandler("my-topic) { record -> myService.save(record) ) } } ``` ### Configuration Options - **schemaRegistryUrl**: Sets the URL for the schema registry. - **topic**: Configures a specific Kafka topic with properties like partitions, replicas, and custom configurations. - **common**: Sets common configurations for Kafka clients, such as bootstrap servers. - **admin**: Configures the Kafka admin client. - **producer**: Configures the Kafka producer client, including `clientId`. - **consumer**: Configures the Kafka consumer client, including `groupId`. - **consumerConfig**: Allows for detailed consumer configuration, including defining `consumerRecordHandler` for processing incoming records. ``` -------------------------------- ### Install Kafka Plugin Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/index.md Installs the Kafka plugin into the Ktor application. ```APIDOC ## Install Kafka Plugin ### Description Installs the Kafka plugin into the Ktor application with the specified configuration. ### Method Extension function on `Application`. ### Function Signature ```kotlin fun Application.installKafka(config: KafkaConfig.() -> Unit) ``` ### Parameters * `config` - A lambda with receiver for `KafkaConfig` to configure the Kafka plugin. ``` -------------------------------- ### Install Kafka Plugin with Consumer Configuration Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-file-config/-kafka.md Install the Kafka plugin and configure a Kafka consumer, including setting up a handler for incoming consumer records. Ensure the 'my-topic' is correctly specified and the 'myService.save' method is implemented. ```kotlin install(Kafka) { consumerConfig { consumerRecordHandler("my-topic) { record -> myService.save(record) ) } } ``` -------------------------------- ### Kafka Plugin Installation Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-file-config/index.md Installs the Kafka plugin for the Ktor server using a configuration path and an optional configuration block. ```APIDOC ## Kafka Plugin Installation ### Description Installs the Kafka plugin with the given KafkaFileConfig block. Allows configuration via a specified path in the application config file. ### Method `fun Application.kafka(configurationPath: String = DEFAULT_CONFIG_PATH, config: KafkaFileConfig.() -> Unit)` ### Parameters - **configurationPath** (String) - Optional - The path to the Kafka configuration in the application config file. Defaults to `DEFAULT_CONFIG_PATH`. - **config** (KafkaFileConfig.() -> Unit) - A lambda function to configure the Kafka settings. ``` -------------------------------- ### Install Kafka Plugin with Code Configuration Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/ktor-server-kafka/README.md Use the Kafka plugin's DSL for comprehensive Kafka configuration within your Ktor application. This method allows programmatic setup of schema registry URL, topics, common client configurations, admin, producer, consumer settings, and schema registration. ```kotlin install(Kafka) { schemaRegistryUrl = "my.schemaRegistryUrl" topic(named("my-topic")) { partitions = 1 replicas = 1 configs { messageTimestampType = CreateTime } } common { // <-- Define common configs bootstrapServers = listOf("my-kafka") retries = 1 clientId = "my-client-id" } admin { } // <-- Creates an admin client producer { // <-- Creates a producer clientId = "my-client-id" } consumer { // <-- Creates a consumer groupId = "my-group-id" clientId = "my-client-id-override" //<-- Override common configurations } consumerConfig { consumerRecordHandler(named("my-topic")) { record -> myService.save(record) } } registerSchemas { using { // <-- optionally provide a client, by default CIO is used HttpClient() } MyRecord::class at named("my-topic") // <-- Will register schema upon startup } } ``` -------------------------------- ### Install Kafka Plugin with File Configuration Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/ktor-server-kafka/README.md Install the Kafka plugin using an application configuration file, specifying consumer handlers and schema registration. The plugin defaults to looking for configuration in `ktor.kafka` but can be pointed to a custom path. ```kotlin install(KafkaFromFileConfig.Kafka) { consumerConfig { consumerRecordHandler("my-topic") { record -> myService.save(record) } } registerSchemas { MyRecord::class at named("my-topic") // <-- Will register schema upon startup } } ``` ```kotlin install(KafkaFromFileConfig.Kafka("ktor.my.kafka")){ ... } ``` -------------------------------- ### Configure Kafka Plugin with Kotlin DSL Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Installs and configures Kafka admin, producer, and consumer clients using a Kotlin DSL. Topics are created automatically, Avro schemas can be registered on startup, and a background consumer loop is started when the application starts. Access Kafka clients via application.kafkaAdminClient, application.kafkaProducer, etc. ```kotlin import io.github.flaxoos.ktor.server.plugins.kafka.Kafka import io.github.flaxoos.ktor.server.plugins.kafka.TopicName.Companion.named import io.github.flaxoos.ktor.server.plugins.kafka.components.MessageTimestampType.CreateTime import io.github.flaxoos.ktor.server.plugins.kafka.kafkaAdminClient import io.github.flaxoos.ktor.server.plugins.kafka.kafkaProducer import io.ktor.server.application.install import io.ktor.server.application.Application import org.apache.avro.generic.GenericRecordBuilder import org.apache.kafka.clients.producer.ProducerRecord fun Application.configureKafka() { install(Kafka) { schemaRegistryUrl = "http://schema-registry:8081" topic(named("events")) { partitions = 3 replicas = 1 configs { messageTimestampType = CreateTime retentionMs = 604_800_000L // 7 days } } common { bootstrapServers = listOf("kafka:9092") retries = 3 clientId = "my-service" } admin { } // creates AdminClient; accessible via application.kafkaAdminClient producer { clientId = "my-service-producer" acks = "all" enableIdempotence = true } consumer { groupId = "my-service-group" autoOffsetReset = "earliest" enableAutoCommit = false } consumerConfig { consumerPollFrequency = 500.milliseconds consumerRecordHandler(named("events")) { record -> // record: ConsumerRecord println("Received key=${record.key()} value=${record.value()}") // persist, transform, forward … } } registerSchemas { using { HttpClient(CIO) } // optional: provide a custom HTTP client MyAvroRecord::class at named("events") // registers schema on startup } } } // Accessing clients anywhere in the application after installation: fun Application.sendEvent(payload: GenericRecord) { kafkaProducer?.send(ProducerRecord("events", "key-1", payload)) //kafkaAdminClient, kafkaConsumer, kafkaConsumerJob also available } ``` -------------------------------- ### Kafka Plugin Installation Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-file-config/-kafka.md Installs the Kafka plugin for the Ktor server, configuring it via a specified path in the application's configuration file. ```APIDOC ## Kafka Plugin ### Description Plugin for setting up a kafka client, configured in application config file. ### Installation ```kotlin install(Kafka) { consumerConfig { consumerRecordHandler("my-topic) { record -> myService.save(record) ) } } ``` ### Parameters - `configurationPath` (String): The path to the configuration in the application configuration file. - `config` (KafkaFileConfig.KafkaConsumerConfig.() -> Unit): Configuration block for the plugin. ``` -------------------------------- ### installKafka Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/install-kafka.md Installs the Kafka plugin with a provided configuration block. ```APIDOC ## installKafka ### Description Installs the Kafka plugin with the given KafkaConfig block. ### Signature ```kotlin fun Application.installKafka(config: KafkaConfig.() -> Unit) ``` ### Parameters * `config` - A lambda function that configures the Kafka plugin using `KafkaConfig`. ``` -------------------------------- ### Configure Kafka Plugin from Code Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-kafka/index.md Install and configure the Kafka plugin using a DSL directly in your Ktor application code. This allows for detailed setup of schema registry, topics, common configurations, admin, producer, consumer clients, and schema registration. ```kotlin install(Kafka) { schemaRegistryUrl = listOf("my.schemaRegistryUrl") topic(named("my-topic")) { partitions = 1 replicas = 1 configs { messageTimestampType = CreateTime } } common { // <-- Define common configs bootstrapServers = listOf("my-kafka") retries = 1 clientId = "my-client-id" } admin { } // <-- Creates an admin client producer { // <-- Creates a producer clientId = "my-client-id" } consumer { // <-- Creates a consumer groupId = "my-group-id" clientId = "my-client-id-override" //<-- Override common configurations } consumerConfig { consumerRecordHandler(named("my-topic")) { record -> myService.save(record) } } registerSchemas { using { // <-- optionally provide a client, by default CIO is used HttpClient() } MyRecord::class at named("my-topic") // <-- Will register schema upon startup } } ``` -------------------------------- ### Kafka Plugin Installation Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-file-config/kafka.md Installs the Kafka plugin for the Ktor application. It allows for custom configuration via a lambda block. ```APIDOC ## kafka Plugin Installation ### Description Installs the Kafka plugin with the given KafkaFileConfig block. This allows for customization of Kafka-related settings. ### Method Signature ```kotlin fun Application.kafka( configurationPath: String = DEFAULT_CONFIG_PATH, config: KafkaFileConfig.() -> Unit ) ``` ### Parameters - **configurationPath** (String) - Optional - The path to the configuration file. Defaults to `DEFAULT_CONFIG_PATH`. - **config** (KafkaFileConfig.() -> Unit) - Required - A lambda block to configure Kafka settings. ``` -------------------------------- ### Install and Configure Task Scheduling Plugin Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-task-scheduling/index.md Install the TaskScheduling plugin in your Ktor application and define one or more task managers. The first manager defined becomes the default. ```kotlin install(TaskScheduling){ redis{ //<-- this will be the default manager ... } jdbc("my jdbc manager"){ ... } } ``` -------------------------------- ### Configure Kafka Plugin Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-kafka.md Install and configure the Kafka plugin with schema registry, topics, common settings, admin client, producer, and consumer handlers. Use this to set up Kafka integration in your Ktor application. ```kotlin install(Kafka) { schemaRegistryUrl = listOf(super.schemaRegistryUrl) topic(it) { partitions = 1 replicas = 1 configs { messageTimestampType = CreateTime } } common { bootstrapServers = listOf("my-kafka") } admin { } // will create an admin producer { clientId = "my-client-id" } // will create a producer consumer { groupId = "my-group-id" } // will create a consumer consumerConfig { consumerRecordHandler("my-topic) { record -> myService.save(record) ) } } ``` -------------------------------- ### Detailed RateLimiting Plugin Configuration Options Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/ktor-server-rate-limiting/README.md Provides a comprehensive example of configuring various aspects of the RateLimiting plugin, including rate limiter strategy, timing, capacity, clock source, call volume unit, whitelisting/blacklisting by host, principal, and agent, and custom handlers for accepted calls, exceeded limits, and blacklisted callers. ```kotlin install(RateLimiting) { // Configuring Rate Limiter type = TokenBucket::class, // Using Token Bucket rate limiting strategy rate = 10.milliseconds, // 1 token is added per 10 milliseconds capacity = 1000, // Up to 1000 tokens can be held for bursty traffic clock = { Clock.System.now().toEpochMilliseconds() }, // Using system time callVolumeUnit = CallVolumeUnit.Calls() // Measuring by the number of API calls ) // Whitelisting Configurations whiteListedHosts = setOf("192.168.1.1") // IP address exempted from rate limiting whiteListedPrincipals = setOf(Principal("trustedUser")) // Trusted user with unrestricted access whiteListedAgents = setOf("trusted-agent") // A user-agent that is allowed unrestricted access // Blacklisting Configurations blackListedHosts = setOf("192.168.1.2") // IP address completely restricted from API access blackListedPrincipals = setOf(Principal("maliciousUser")) // User that is denied access to the API blackListedAgents = setOf("malicious-agent") // A user-agent that is blocked from making API calls // Handlers blackListedCallerCallHandler = { call -> // Respond with a 403 Forbidden status to blacklisted callers call.respond(HttpStatusCode.Forbidden, "You are blacklisted and cannot access the API.") } callAcceptedHandler = { notLimited -> // Add rate-limiting headers for accepted calls response.headers.append("X-RateLimit-Remaining", "${notLimited.remaining}") response.headers.append("X-RateLimit-Measured-by", notLimited.rateLimiter.callVolumeUnit.name) } rateLimitExceededHandler = { limitedBy -> // Respond with a 429 status and appropriate headers for rate-limited callers respond(HttpStatusCode.TooManyRequests, "Rate limit exceeded: ${limitedBy.message}") response.headers.append("X-RateLimit-Limit", "${limitedBy.rateLimiter.capacity}") response.headers.append("X-RateLimit-Measured-by", limitedBy.rateLimiter.callVolumeUnit.name) response.headers.append("X-RateLimit-Reset", "${limitedBy.resetIn.inWholeMilliseconds}") } } ``` -------------------------------- ### Conventional Commit Examples Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/RELEASING.md Examples of conventional commit messages and their impact on versioning. Use these prefixes for proper version calculation and changelog generation. ```markdown | Commit Type | Version Impact | |-------------|----------------| | `feat:` | Minor bump | | `fix:` | Patch bump | | `perf:` | Patch bump | | `BREAKING CHANGE:` | Major bump | | `docs:`, `test:`, etc. | Patch bump | ``` -------------------------------- ### Install and Configure Circuit Breaker Plugin for HttpClient Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Installs the CircuitBreaking plugin on a Ktor HttpClient, allowing configuration of global and named circuit breakers. States cycle through CLOSED, OPEN, and HALF_OPEN. ```kotlin import io.github.flaxoos.ktor.client.plugins.circuitbreaker.CircuitBreaking import io.github.flaxoos.ktor.client.plugins.circuitbreaker.CircuitBreakerName.Companion.toCircuitBreakerName import io.github.flaxoos.ktor.client.plugins.circuitbreaker.requestWithCircuitBreaker import io.ktor.client.HttpClient import io.ktor.client.engine.cio.CIO import io.ktor.http.HttpMethod.Companion.Get val httpClient = HttpClient(CIO) { install(CircuitBreaking) { // Global circuit breaker — used when no named breaker is specified config.global { failureThreshold = 5 // open after 5 failures halfOpenFailureThreshold = 2 // close only if < 2 failures while half-open resetInterval = 10.seconds // wait 10 s before probing again failureTrigger = { status.value >= 500 } // only 5xx counts as failure } // Named circuit breaker — more sensitive, for a critical upstream config.register("payments".toCircuitBreakerName()) { failureThreshold = 2 halfOpenFailureThreshold = 1 resetInterval = 30.seconds failureTrigger = { status.value >= 400 } // treat 4xx as failure too } } } // --- Usage --- suspend fun fetchUser(id: String) = try { // Uses the global circuit breaker httpClient.requestWithCircuitBreaker { method = Get url("https://user-service/users/$id") } } catch (e: CircuitBreakerException) { // Circuit is OPEN — fail fast, no network call made println("User service unavailable: ${e.message}") null } suspend fun chargeCard(amount: Int) = try { // Uses the named "payments" breaker via requestWithCircuitBreaker httpClient.requestWithCircuitBreaker(name = "payments".toCircuitBreakerName()) { method = Post url("https://payment-service/charge") setBody(mapOf("amount" to amount)) } } catch (e: CircuitBreakerException) { println("Payment service circuit open: ${e.message}") null } ``` -------------------------------- ### Access Kafka Clients in Ktor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-kafka/index.md Retrieve initialized Kafka Admin, Producer, and Consumer clients from the Ktor application instance after the Kafka plugin has been installed and configured. ```kotlin val adminClient = application.kafkaAdminClient val producer = application.kafkaProducer val consumer = application.kafkaConsumer ``` -------------------------------- ### Implement Rate Limiting with Token Bucket Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Installs a per-route rate limiter using the Token Bucket algorithm. Supports whitelisting, blacklisting, custom 429 responses, and X-RateLimit-* headers. ```kotlin import io.github.flaxoos.ktor.server.plugins.ratelimiter.RateLimiting import io.github.flaxoos.ktor.server.plugins.ratelimiter.CallVolumeUnit import io.github.flaxoos.ktor.server.plugins.ratelimiter.implementations.TokenBucket import io.ktor.http.HttpStatusCode import io.ktor.server.application.install import io.ktor.server.response.respond import io.ktor.server.routing.get import io.ktor.server.routing.route import io.ktor.server.routing.routing import kotlin.time.Duration.Companion.seconds fun Application.configureRateLimiting() { routing { route("/api/v1") { install(RateLimiting) { rateLimiter { type = TokenBucket::class rate = 1.seconds // 1 token replenished per second capacity = 60 // max 60 tokens (burst up to 60 req) callVolumeUnit = CallVolumeUnit.Calls() // count by calls (default) } // Bypass rate limiting for trusted hosts / users whiteListedHosts = setOf("127.0.0.1", "10.0.0.0/8") whiteListedAgents = setOf("internal-health-checker") // Block bad actors outright (→ 403) blackListedHosts = setOf("192.0.2.99") blackListedAgents = setOf("BadBot/1.0") blackListedCallerCallHandler = { call -> call.respond(HttpStatusCode.Forbidden, "Access denied") } // Append remaining capacity headers on every accepted call callAcceptedHandler = { notLimited -> response.headers.append("X-RateLimit-Remaining", "${notLimited.remaining}") } // Custom 429 handler with reset hint rateLimitExceededHandler = { limited -> respond( HttpStatusCode.TooManyRequests, "Too many requests. Retry after ${limited.resetIn.inWholeSeconds}s", ) response.headers.append("Retry-After", "${limited.resetIn.inWholeSeconds}") } // Exclude health check endpoint excludePaths = setOf(Regex("health")) } get("/items") { call.respond("OK") } } } } ``` -------------------------------- ### Access Kafka Clients in Ktor Application Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/ktor-server-kafka/README.md After installing the Kafka plugin, you can access the initialized Kafka Admin Client, Producer, and Consumer instances directly from the Ktor application object. ```kotlin val adminClient = application.kafkaAdminClient val producer = application.kafkaProducer val consumer = application.kafkaConsumer ``` -------------------------------- ### Configure Task Scheduling with JDBC Lock Manager Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Installs the Task Scheduling plugin using Jetbrains Exposed for JDBC-based distributed locking. The database connection details must be provided. ```kotlin import io.github.flaxoos.ktor.server.plugins.taskscheduling.TaskScheduling import io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database.jdbc import org.jetbrains.exposed.v1.jdbc.Database fun Application.configureJdbcScheduling() { val db = Database.connect( url = "jdbc:postgresql://postgres:5432/mydb", driver = "org.postgresql.Driver", user = "app", password = "secret", ) install(TaskScheduling) { jdbc { // default manager database = db } task { name = "sync-external-data" kronSchedule = { minutes { every(15) } } task = { _ -> externalSyncService.sync() } } } } ``` -------------------------------- ### Example HOCON Configuration for Kafka Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/ktor-server-kafka/README.md This HOCON configuration defines Kafka settings including schema registry URL, common client properties, admin, consumer, producer configurations, and topic definitions with their specific settings. ```hocon ktor { kafka { schema.registry.url = ["SCHEMA_REGISTRY_URL"] common { "bootstrap.servers" = ["BOOTSTRAP_SERVERS"] # Additional configuration } admin { ##Additional configuration } consumer { "group.id" = "my-group-id" # Additional configuration } producer { "client.id" = "my-client-id" # Additional configuration } topics = [ { name = my-topic partitions = 1 replicas = 1 configs { "message.timestamp.type" = CreateTime # Additional configuration } } ] } } ``` -------------------------------- ### Configure Task Scheduling with MongoDB Lock Manager Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Installs the Task Scheduling plugin using MongoDB transactions for distributed locking. Requires a MongoDB client and database name. ```kotlin import io.github.flaxoos.ktor.server.plugins.taskscheduling.TaskScheduling import io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database.mongoDb import com.mongodb.kotlin.client.coroutine.MongoClient fun Application.configureMongoScheduling() { val mongoClient = MongoClient.create("mongodb://mongo:27017") install(TaskScheduling) { mongoDb { client = mongoClient databaseName = "myapp" } task { name = "recalculate-metrics" concurrency = 2 // 2 concurrent instances allowed kronSchedule = { hours { every(1) } minutes { at(30) } } task = { executionTime -> metricsService.recalculate(executionTime) } } } } ``` -------------------------------- ### Configure Circuit Breaker Plugin Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-client-circuit-breaker/index.md Install and configure the CircuitBreaking plugin within your HttpClient. You can set global defaults and register named circuit breakers for specific configurations. ```kotlin HttpClient { install(CircuitBreaking) { config.global { failureThreshold = 10 halfOpenFailureThreshold = 5 resetInterval = 100.milliseconds } config.register("strict".toCircuitBreakerName()) { failureThreshold = 2 halfOpenFailureThreshold = 1 resetInterval = 1.seconds } } } ``` -------------------------------- ### init Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers/-task-manager/index.md Initializes the TaskManager with a list of tasks it will manage. ```APIDOC ## init ### Description Initialize the TaskManager with the given tasks it manages. ### Signature abstract suspend fun init(tasks: List) ### Parameters * **tasks** (List) - A list of tasks to be managed by the TaskManager. ``` -------------------------------- ### init Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-mongo-d-b-lock-manager/index.md Initializes the lock manager with a list of tasks. ```APIDOC ## init ### Description Initializes the lock manager with a list of tasks. This method is part of the initialization process for the task scheduling system. ### Method Signature suspend override fun init(tasks: List) ### Parameters - **tasks** (List) - A list of tasks to be initialized within the lock manager. ``` -------------------------------- ### SchemaRegistryClient Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka.components/-schema-registry-client/index.md Initializes a new instance of the SchemaRegistryClient. ```APIDOC ## SchemaRegistryClient Constructor ### Description Initializes a new instance of the SchemaRegistryClient with a provided HTTP client, the schema registry URL, and a timeout in milliseconds. ### Parameters * **providedClient** (HttpClient) - The HTTP client to use for making requests. * **schemaRegistryUrl** (String) - The URL of the schema registry. * **timeoutMs** (Long) - The timeout for requests in milliseconds. ``` -------------------------------- ### init Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.redis/-redis-lock-manager/index.md Initializes the RedisLockManager with a list of tasks. ```APIDOC ## init ### Description Initializes the RedisLockManager with a list of tasks that it will manage. ### Method `suspend override fun init(tasks: List)` ### Parameters * **tasks** (List) - A list of tasks to be managed by the lock manager. ``` -------------------------------- ### connectionAcquisitionTimeoutMs Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.redis/-redis-task-lock-manager-configuration/connection-acquisition-timeout-ms.md The timeout in milliseconds for trying to get a connection from the pool. ```APIDOC ## connectionAcquisitionTimeoutMs ### Description Specifies the timeout duration in milliseconds for attempting to acquire a connection from the connection pool. ### Property - **connectionAcquisitionTimeoutMs** (Long) - The timeout value in milliseconds. ``` -------------------------------- ### init Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-database-task-lock-manager/init.md Initializes the TaskManager with the given tasks it manages. ```APIDOC ## init ### Description Initializes the TaskManager with the given tasks it manages. ### Signature suspend override fun init(tasks: List) ### Parameters #### Path Parameters - **tasks** (List) - Description: The list of tasks to be managed. ``` -------------------------------- ### using Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-schema-registration-builder/index.md Optionally provides an HttpClient for schema registration. ```APIDOC ## using ### Description Optionally provides a client to register schemas. By default, CIO would be used. In any case, the client would be configured with serialization json and the configured `AbstractKafkaConfig.schemaRegistrationTimeoutMs`. ### Method Signature `fun using(provider: () -> HttpClient)` ### Parameters * **provider** (`() -> HttpClient`) - A function that provides an `HttpClient` instance. ``` -------------------------------- ### acquireLockKey Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock/-task-lock-manager/index.md Acquires a lock key to get permission to execute a task. This is an abstract function that must be implemented by concrete subclasses. ```APIDOC ## acquireLockKey ### Description Get permission to execute the task. ### Method `abstract suspend fun acquireLockKey(task: Task, executionTime: DateTime, concurrencyIndex: Int): TASK_LOCK?` ### Parameters * **task** (Task) - The task to acquire a lock for. * **executionTime** (DateTime) - The scheduled execution time. * **concurrencyIndex** (Int) - The concurrency index for the task. ``` -------------------------------- ### init Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-jdbc-lock-manager/index.md Initializes the JdbcLockManager with a list of tasks. ```APIDOC ## init ### Description Initializes the JdbcLockManager with a list of tasks. This method is typically called during the application startup. ### Signature suspend override fun init(tasks: List) ### Parameters - **tasks** (List) - A list of tasks to be managed by the lock manager. ``` -------------------------------- ### Column Reference Extensions Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-exposed-task-lock-table/index.md Extension functions for columns to easily establish references to other columns, simplifying foreign key setup. ```APIDOC ## Column Reference Extensions These extension functions provide a concise way to set up references between columns. ### `infix fun , S : T, C : Column> C.references(ref: Column): C` Establishes a reference from the current column to another column. ### `fun , S : T, C : Column> C.references(ref: Column, onDelete: ReferenceOption?, onUpdate: ReferenceOption?, fkName: String?): C` Establishes a reference with explicit control over delete and update options, and an optional foreign key name. ### `fun , S : T, C : Column> C.references(ref: Column>, onDelete: ReferenceOption?, onUpdate: ReferenceOption?, fkName: String?): C` Establishes a reference to a column of `EntityID` type with explicit control over delete and update options, and an optional foreign key name. ``` -------------------------------- ### MongoDBJobLockManagerConfiguration() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-mongo-d-b-job-lock-manager-configuration/-mongo-d-b-job-lock-manager-configuration.md The default constructor for MongoDBJobLockManagerConfiguration. It initializes the configuration with default values, allowing for easy setup of the MongoDB job lock manager. ```APIDOC ## MongoDBJobLockManagerConfiguration() ### Description Initializes a new instance of the `MongoDBJobLockManagerConfiguration` class with default settings. ### Constructor Signature `constructor()` ### Usage This constructor is used when you want to create a `MongoDBJobLockManagerConfiguration` object without specifying custom connection details or other parameters, relying on the default configuration provided by the library. ``` -------------------------------- ### CallVolumeUnit Interface Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.ratelimiter/-call-volume-unit/index.md The CallVolumeUnit interface is an abstract representation for measuring call volume. It defines methods to get the size of a call and its abstract name. ```APIDOC ## Interface CallVolumeUnit ### Description Represents a unit for measuring the volume of calls. This interface is implemented by specific units like Bytes and Calls to define how call volume is quantified. ### Abstract Properties - **name** (String) - The abstract name of the volume unit. - **size** (Int) - The abstract size associated with the volume unit. ### Abstract Functions - **callSize**(call: ApplicationCall): Double - Abstract function to calculate the size of a given call based on this unit. - **size**(): Double - Returns the size as a Double. ``` -------------------------------- ### TaskSchedulingConfiguration() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling/-task-scheduling-configuration/-task-scheduling-configuration.md Initializes a new instance of the TaskSchedulingConfiguration class. This is the default constructor. ```APIDOC ## TaskSchedulingConfiguration() ### Description Initializes a new instance of the TaskSchedulingConfiguration class. ### Constructor Signature `constructor()` ``` -------------------------------- ### beforeEach Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling/-task-scheduling-plugin-test/index.md Sets up a callback function to be executed before each test case. ```APIDOC ## beforeEach ### Description Sets up a callback function to be executed before each test case. This can be used for common setup logic. ### Signature ```kotlin open suspend fun beforeEach(f: suspend (TestCase) -> Unit) open suspend fun beforeEach(testCase: TestCase) ``` ### Parameters * `f` (suspend (TestCase) -> Unit) - The callback function to execute before each test. * `testCase` (TestCase) - The current test case being executed. ``` -------------------------------- ### Configure Kafka with File-Based Configuration Source: https://context7.com/flaxoos/extra-ktor-plugins/llms.txt Loads Kafka configuration from application.conf. Define consumer handlers and schema registrations in code. ```kotlin // application.conf ktor { kafka { schema.registry.url = "http://schema-registry:8081" common { "bootstrap.servers" = "kafka:9092" "retries" = 3 "client.id" = "my-service" } admin {} producer { "client.id" = "my-service-producer" } consumer { "group.id" = "my-service-group" "auto.offset.reset" = "earliest" } topics = [ { name = events, partitions = 3, replicas = 1 } ] } } // Application.kt import io.github.flaxoos.ktor.server.plugins.kafka.FileConfig fun Application.configureKafka() { // Uses "ktor.kafka" path by default install(FileConfig.Kafka) { consumerConfig { consumerRecordHandler("events") { record -> println("key=${record.key()} value=${record.value()}") } } registerSchemas { MyAvroRecord::class at named("events") } } // Or specify a custom config path: // install(FileConfig.Kafka("ktor.messaging.kafka")) { … } } ``` -------------------------------- ### clock Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.ratelimiter.implementations/-sliding-window/clock.md The clock property is an open override val of type () -> Long, representing a time provider. It is used to get the current time, typically in milliseconds, for rate limiting calculations. ```APIDOC ## clock ### Description A time provider used by the SlidingWindow rate limiter. ### Property - **clock** (`() -> Long`): An open override property that returns a Long representing the current time. ``` -------------------------------- ### build() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-consumer-properties-builder/build.md Builds and returns KafkaProperties. ```APIDOC ## build() ### Description Builds and returns KafkaProperties. ### Signature ```kotlin open override fun build(): KafkaProperties ``` ``` -------------------------------- ### TaskSchedulingPluginTest() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling/-task-scheduling-plugin-test/-task-scheduling-plugin-test.md Initializes a new instance of the TaskSchedulingPluginTest class. ```APIDOC ## TaskSchedulingPluginTest() ### Description Initializes a new instance of the TaskSchedulingPluginTest class. ### Constructor `constructor()` ``` -------------------------------- ### Test Release Configuration Script Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/RELEASING.md Run this script locally to validate version generation for snapshot and release modes, ensuring no unwanted tags are created. ```bash ./test-release-config.sh ``` -------------------------------- ### TokenBucket Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.ratelimiter.implementations/-token-bucket/-token-bucket.md Initializes a new instance of the TokenBucket class with specified rate, capacity, and optional logger and clock. ```APIDOC ## TokenBucket Constructor ### Description Initializes a new instance of the TokenBucket class. ### Parameters * **log** (KLogger) - Optional - The logger instance to use for logging. * **rate** (Duration) - Required - The rate at which tokens are refilled. * **callVolumeUnit** (CallVolumeUnit) - Optional - The unit for measuring call volume, defaults to Calls(). * **capacity** (Int) - Required - The maximum number of tokens the bucket can hold. * **clock** (() -> Long) - Optional - A function that returns the current time in milliseconds, defaults to system clock. ``` -------------------------------- ### Add Ktor Server and Client Plugins Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/README.md Include these dependencies in your project to add the extra Ktor plugins. Ensure you replace `ktor_plugins_version` with the latest version. ```kotlin dependencies { implementation("io.github.flaxoos:ktor-server-kafka:$ktor_plugins_version") implementation("io.github.flaxoos:ktor-server-task-scheduling-$module:$ktor_plugins_version") implementation("io.github.flaxoos:ktor-server-rate-limiting:$ktor_plugins_version") implementation("io.github.flaxoos:ktor-client-circuit-breaker:$ktor_plugins_version") } ``` -------------------------------- ### Task Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.tasks/-task/index.md Constructs a new Task instance. ```APIDOC ## Task Constructor ### Description Initializes a new Task with the specified name, dispatcher, concurrency limit, cron schedule, and the task's execution logic. ### Parameters - **name** (String) - The unique name of the task. - **dispatcher** (CoroutineDispatcher?) - The CoroutineDispatcher to use for executing the task. If null, the default dispatcher will be used. - **concurrency** (Int) - The maximum number of concurrent executions allowed for this task. - **kronSchedule** (KronScheduler) - The schedule defining when the task should run. - **task** (suspend Application.(DateTime) -> Unit) - The suspend function that contains the actual task logic. It receives the Application instance and the current DateTime when executed. ``` -------------------------------- ### KafkaConsumerConfig Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-kafka-consumer-config/index.md Initializes a new instance of the KafkaConsumerConfig class with default settings. ```APIDOC ## KafkaConsumerConfig() ### Description Initializes a new instance of the KafkaConsumerConfig class. ### Constructor `KafkaConsumerConfig()` ``` -------------------------------- ### SchemaRegistryClient Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka.components/-schema-registry-client/-schema-registry-client.md Initializes a new instance of the SchemaRegistryClient with the specified HttpClient, schema registry URL, and timeout. ```APIDOC ## SchemaRegistryClient constructor ### Description Initializes a new instance of the SchemaRegistryClient. ### Parameters #### Path Parameters - **providedClient** (HttpClient) - Description not available. - **schemaRegistryUrl** (String) - The URL of the schema registry. - **timeoutMs** (Long) - The timeout in milliseconds for operations. ``` -------------------------------- ### beforeTest Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling/-task-scheduling-plugin-test/index.md Sets up a callback function to be executed before each individual test. ```APIDOC ## beforeTest ### Description Sets up a callback function to be executed before each individual test within a test case. This allows for test-specific setup. ### Signature ```kotlin open suspend fun beforeTest(testCase: TestCase) open override fun beforeTest(f: suspend (TestCase) -> Unit) ``` ### Parameters * `testCase` (TestCase) - The current test case being executed. * `f` (suspend (TestCase) -> Unit) - The callback function to execute before the test. ``` -------------------------------- ### SchemaRegistrationBuilder.using Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-schema-registration-builder/using.md Allows you to optionally provide an HttpClient for schema registration. If not provided, CIO will be used by default. The client will be configured with JSON serialization and the schema registration timeout. ```APIDOC ## using ### Description Optionally provide a client to register schemas. By default, CIO would be used. In any case, the client would be configured with serialization json and the configured `AbstractKafkaConfig.schemaRegistrationTimeoutMs`. ### Method Signature ```kotlin fun using(provider: () -> HttpClient) ``` ### Parameters * **provider** (`() -> HttpClient`) - A function that provides an `HttpClient` instance. ``` -------------------------------- ### DatabaseTaskLockManagerConfiguration() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-database-task-lock-manager-configuration/-database-task-lock-manager-configuration.md Initializes a new instance of the DatabaseTaskLockManagerConfiguration class with default settings. ```APIDOC ## DatabaseTaskLockManagerConfiguration() ### Description This is the default constructor for the `DatabaseTaskLockManagerConfiguration` class. It allows for the creation of a configuration object with its default values, which can then be optionally modified. ### Method constructor() ### Parameters This constructor does not take any parameters. ### Request Example ```kotlin val config = DatabaseTaskLockManagerConfiguration() ``` ### Response This constructor does not return a value directly, but it initializes a `DatabaseTaskLockManagerConfiguration` object. ``` -------------------------------- ### TaskManager init function Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers/-task-manager/init.md Initializes the TaskManager with the tasks it will manage. ```APIDOC ## init ### Description Initializes the TaskManager with the given tasks it manages. ### Signature abstract suspend fun init(tasks: List) ### Parameters #### Path Parameters - **tasks** (List) - Description: The list of tasks to be managed by the TaskManager. ``` -------------------------------- ### SchemaRegistrationBuilder constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-schema-registration-builder/index.md Initializes a new instance of the SchemaRegistrationBuilder. ```APIDOC ## SchemaRegistrationBuilder() ### Description Constructs a new SchemaRegistrationBuilder. ### Constructor SchemaRegistrationBuilder() ``` -------------------------------- ### SlidingWindow Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.ratelimiter.implementations/-sliding-window/index.md Initializes a new instance of the SlidingWindow rate limiter. ```APIDOC ## SlidingWindow Constructor ### Description Constructs a SlidingWindow rate limiter with the specified rate, capacity, call volume unit, and an optional clock function. ### Parameters - **rate** (Duration) - The time duration over which calls are counted. - **capacity** (Int) - The maximum number of calls allowed within the rate duration. - **callVolumeUnit** (CallVolumeUnit) - Defines the weight of each call. - **clock** (Function0) - Optional function to get the current time in milliseconds. Defaults to the current system time. ``` -------------------------------- ### TopicPropertiesBuilder Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-topic-properties-builder/index.md Initializes a new instance of the TopicPropertiesBuilder class. ```APIDOC ## TopicPropertiesBuilder() ### Description Constructs a new TopicPropertiesBuilder. ### Constructor Signature ```kotlin constructor () ``` ``` -------------------------------- ### Detailed Rate Limiting Configuration Options Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/ktor-server-rate-limiting/index.md Provides a comprehensive overview of the configuration options available for the RateLimiting plugin. This includes setting the rate limiter type, rate, capacity, clock, call volume unit, and various whitelisting/blacklisting rules, as well as custom handlers for different scenarios. ```kotlin install(RateLimiting) { // Configuring Rate Limiter type = TokenBucket::class, // Using Token Bucket rate limiting strategy rate = 10.milliseconds, // 1 token is added per 10 milliseconds capacity = 1000, // Up to 1000 tokens can be held for bursty traffic clock = { Clock.System.now().toEpochMilliseconds() }, // Using system time callVolumeUnit = CallVolumeUnit.Calls() // Measuring by the number of API calls ) // Whitelisting Configurations whiteListedHosts = setOf("192.168.1.1") // IP address exempted from rate limiting whiteListedPrincipals = setOf(Principal("trustedUser")) // Trusted user with unrestricted access whiteListedAgents = setOf("trusted-agent") // A user-agent that is allowed unrestricted access // Blacklisting Configurations blackListedHosts = setOf("192.168.1.2") // IP address completely restricted from API access blackListedPrincipals = setOf(Principal("maliciousUser")) // User that is denied access to the API blackListedAgents = setOf("malicious-agent") // A user-agent that is blocked from making API calls // Handlers blackListedCallerCallHandler = { call -> // Respond with a 403 Forbidden status to blacklisted callers call.respond(HttpStatusCode.Forbidden, "You are blacklisted and cannot access the API.") } callAcceptedHandler = { notLimited -> // Add rate-limiting headers for accepted calls response.headers.append("X-RateLimit-Remaining", "${notLimited.remaining}") response.headers.append("X-RateLimit-Measured-by", notLimited.rateLimiter.callVolumeUnit.name) } rateLimitExceededHandler = { limitedBy -> // Respond with a 429 status and appropriate headers for rate-limited callers response.headers.append("X-RateLimit-Limit", "${limitedBy.rateLimiter.capacity}") response.headers.append("X-RateLimit-Measured-by", limitedBy.rateLimiter.callVolumeUnit.name) response.headers.append("X-RateLimit-Reset", "${limitedBy.resetIn.inWholeMilliseconds}") respond(HttpStatusCode.TooManyRequests, "Rate limit exceeded: ${limitedBy.message}") } ``` -------------------------------- ### AdminPropertiesBuilder Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/-admin-properties-builder/index.md Initializes a new instance of the AdminPropertiesBuilder class. ```APIDOC ## AdminPropertiesBuilder() ### Description Constructs a new AdminPropertiesBuilder. ### Constructor `AdminPropertiesBuilder()` ``` -------------------------------- ### Kafka Consumer Configuration (Abstract) Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.kafka/index.md Provides a configuration block for Kafka consumer settings. ```APIDOC ## Kafka Consumer Configuration (Abstract) ### Description Provides a configuration block for Kafka consumer settings. ### Method Extension function on `AbstractKafkaConfig`. ### Function Signature ```kotlin fun AbstractKafkaConfig.consumerConfig(configuration: KafkaConsumerConfig.() -> Unit) = {} ``` ### Parameters * `configuration` - A lambda with receiver for `KafkaConsumerConfig` to configure consumer settings. ``` -------------------------------- ### TaskManager() Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers/-task-manager/-task-manager.md Initializes a new instance of the TaskManager class. ```APIDOC ## TaskManager() ### Description Initializes a new instance of the TaskManager class. ### Constructor TaskManager() ``` -------------------------------- ### Constructor Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.ratelimiter/-call-volume-unit/-bytes/index.md Constructs a Bytes object with the specified size. ```APIDOC ## Constructor Bytes [common] constructor(size: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.md)) ``` -------------------------------- ### initTaskLockTable Source: https://github.com/flaxoos/extra-ktor-plugins/blob/main/documentation/mkdocs/docs/dokka/extra-ktor-plugins/io.github.flaxoos.ktor.server.plugins.taskscheduling.managers.lock.database/-database-task-lock-manager/init-task-lock-table.md Creates the task lock key table in the database. ```APIDOC ## initTaskLockTable ### Description Creates the task lock key table in the database. ### Signature abstract suspend fun initTaskLockTable() ### Remarks This function is part of the `DatabaseTaskLockManager` and is used to set up the necessary database structure for managing task locks. ```