
Offline queue module for Superkassa
A lightweight, clean-architecture Kotlin Multiplatform (KMP) library providing offline command queuing and synchronization mechanisms for the Superkassa fiscalization system.
It encapsulates queue management, retry policies with backoff, and distributed lease locking to ensure transaction safety and execution integrity in unstable network environments on both JVM (Server) and iOS/Android client applications.
QueueStoragePort).LeaseLockPort.BackoffPolicy) to schedule retries when processing fails due to network or service errors.Add the dependency to your shared commonMain source set inside build.gradle.kts:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.texport:superkassa-offline-queue:1.0.3")
}
}
}
}You can integrate this library directly into your iOS project using Xcode's Swift Package Manager:
https://github.com/texport/superkassa-offline-queue.git
1.0.3.import kz.mybrain.superkassa.offline_queue.application.model.DispatchResult
import kz.mybrain.superkassa.offline_queue.application.model.DispatchStatus
import kz.mybrain.superkassa.offline_queue.application.policy.DefaultBackoffPolicy
import kz.mybrain.superkassa.offline_queue.application.service.QueueCommandHandler
import kz.mybrain.superkassa.offline_queue.application.service.QueueService
import kz.mybrain.superkassa.offline_queue.domain.model.QueueCommand
import kz.mybrain.superkassa.offline_queue.domain.model.QueueLane
import kz.mybrain.superkassa.offline_queue.domain.model.QueueStatus
// 1. Define command handler
val commandHandler = object : QueueCommandHandler {
override fun handle(command: QueueCommand, renewLock: () -> Boolean): DispatchResult {
println("Processing command: ${command.id}")
// renewLock() can be invoked periodically during long-running tasks
return DispatchResult(status = DispatchStatus.SENT)
}
}
// 2. Initialize Service with your storage and lock implementations
val queueService = QueueService(
storage = myStoragePortImpl,
lockPort = myLeaseLockPortImpl,
handler = commandHandler,
backoffPolicy = DefaultBackoffPolicy(),
ownerId = "node-1"
)
// 3. Process commands
queueService.processBatch(cashboxId = "cashbox-123", lane = QueueLane.OFFLINE, limit = 10)The library defines abstract domain ports for durable storage (QueueStoragePort) and mutual-exclusion locking (LeaseLockPort). Concrete implementations (e.g., Room on Android, CoreData on iOS, or JDBC/Redis on the Server) must be provided by the consumer application.
Легковесная мультиплатформенная библиотека (Kotlin Multiplatform / KMP) для управления локальной очередью команд и асинхронной синхронизации в системе фискализации Superkassa.
Она инкапсулирует логику буферизации, политики повторных попыток с экспоненциальной задержкой (backoff) и распределенную аренду блокировок (lease locking) для обеспечения транзакционной безопасности в нестабильных сетевых условиях на сервере (JVM) и в мобильных приложениях (iOS/Android).
QueueStoragePort.LeaseLockPort).BackoffPolicy.Добавьте зависимость в ваш общий набор исходников commonMain в build.gradle.kts:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.texport:superkassa-offline-queue:1.0.3")
}
}
}
}Вы можете подключить библиотеку непосредственно в iOS приложение с помощью Swift Package Manager в Xcode:
https://github.com/texport/superkassa-offline-queue.git
1.0.3.import kz.mybrain.superkassa.offline_queue.application.model.DispatchResult
import kz.mybrain.superkassa.offline_queue.application.model.DispatchStatus
import kz.mybrain.superkassa.offline_queue.application.policy.DefaultBackoffPolicy
import kz.mybrain.superkassa.offline_queue.application.service.QueueCommandHandler
import kz.mybrain.superkassa.offline_queue.application.service.QueueService
import kz.mybrain.superkassa.offline_queue.domain.model.QueueCommand
import kz.mybrain.superkassa.offline_queue.domain.model.QueueLane
import kz.mybrain.superkassa.offline_queue.domain.model.QueueStatus
// 1. Создание обработчика команд
val commandHandler = object : QueueCommandHandler {
override fun handle(command: QueueCommand, renewLock: () -> Boolean): DispatchResult {
println("Отправка команды: ${command.id}")
// renewLock() может вызываться для продления блокировки при длительных задачах
return DispatchResult(status = DispatchStatus.SENT)
}
}
// 2. Инициализация сервиса с реализацией БД и блокировок
val queueService = QueueService(
storage = myStoragePortImpl,
lockPort = myLeaseLockPortImpl,
handler = commandHandler,
backoffPolicy = DefaultBackoffPolicy(),
ownerId = "node-1"
)
// 3. Запуск обработки пакета команд
queueService.processBatch(cashboxId = "cashbox-123", lane = QueueLane.OFFLINE, limit = 10)Библиотека определяет абстрактные порты предметной области для долговременного хранения (QueueStoragePort) и взаимного исключения параллельного выполнения (LeaseLockPort). Конкретные реализации (например, Room на Android, CoreData в iOS или JDBC/Redis на сервере) должны быть предоставлены вызывающим приложением.
A lightweight, clean-architecture Kotlin Multiplatform (KMP) library providing offline command queuing and synchronization mechanisms for the Superkassa fiscalization system.
It encapsulates queue management, retry policies with backoff, and distributed lease locking to ensure transaction safety and execution integrity in unstable network environments on both JVM (Server) and iOS/Android client applications.
QueueStoragePort).LeaseLockPort.BackoffPolicy) to schedule retries when processing fails due to network or service errors.Add the dependency to your shared commonMain source set inside build.gradle.kts:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.texport:superkassa-offline-queue:1.0.3")
}
}
}
}You can integrate this library directly into your iOS project using Xcode's Swift Package Manager:
https://github.com/texport/superkassa-offline-queue.git
1.0.3.import kz.mybrain.superkassa.offline_queue.application.model.DispatchResult
import kz.mybrain.superkassa.offline_queue.application.model.DispatchStatus
import kz.mybrain.superkassa.offline_queue.application.policy.DefaultBackoffPolicy
import kz.mybrain.superkassa.offline_queue.application.service.QueueCommandHandler
import kz.mybrain.superkassa.offline_queue.application.service.QueueService
import kz.mybrain.superkassa.offline_queue.domain.model.QueueCommand
import kz.mybrain.superkassa.offline_queue.domain.model.QueueLane
import kz.mybrain.superkassa.offline_queue.domain.model.QueueStatus
// 1. Define command handler
val commandHandler = object : QueueCommandHandler {
override fun handle(command: QueueCommand, renewLock: () -> Boolean): DispatchResult {
println("Processing command: ${command.id}")
// renewLock() can be invoked periodically during long-running tasks
return DispatchResult(status = DispatchStatus.SENT)
}
}
// 2. Initialize Service with your storage and lock implementations
val queueService = QueueService(
storage = myStoragePortImpl,
lockPort = myLeaseLockPortImpl,
handler = commandHandler,
backoffPolicy = DefaultBackoffPolicy(),
ownerId = "node-1"
)
// 3. Process commands
queueService.processBatch(cashboxId = "cashbox-123", lane = QueueLane.OFFLINE, limit = 10)The library defines abstract domain ports for durable storage (QueueStoragePort) and mutual-exclusion locking (LeaseLockPort). Concrete implementations (e.g., Room on Android, CoreData on iOS, or JDBC/Redis on the Server) must be provided by the consumer application.
Легковесная мультиплатформенная библиотека (Kotlin Multiplatform / KMP) для управления локальной очередью команд и асинхронной синхронизации в системе фискализации Superkassa.
Она инкапсулирует логику буферизации, политики повторных попыток с экспоненциальной задержкой (backoff) и распределенную аренду блокировок (lease locking) для обеспечения транзакционной безопасности в нестабильных сетевых условиях на сервере (JVM) и в мобильных приложениях (iOS/Android).
QueueStoragePort.LeaseLockPort).BackoffPolicy.Добавьте зависимость в ваш общий набор исходников commonMain в build.gradle.kts:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.texport:superkassa-offline-queue:1.0.3")
}
}
}
}Вы можете подключить библиотеку непосредственно в iOS приложение с помощью Swift Package Manager в Xcode:
https://github.com/texport/superkassa-offline-queue.git
1.0.3.import kz.mybrain.superkassa.offline_queue.application.model.DispatchResult
import kz.mybrain.superkassa.offline_queue.application.model.DispatchStatus
import kz.mybrain.superkassa.offline_queue.application.policy.DefaultBackoffPolicy
import kz.mybrain.superkassa.offline_queue.application.service.QueueCommandHandler
import kz.mybrain.superkassa.offline_queue.application.service.QueueService
import kz.mybrain.superkassa.offline_queue.domain.model.QueueCommand
import kz.mybrain.superkassa.offline_queue.domain.model.QueueLane
import kz.mybrain.superkassa.offline_queue.domain.model.QueueStatus
// 1. Создание обработчика команд
val commandHandler = object : QueueCommandHandler {
override fun handle(command: QueueCommand, renewLock: () -> Boolean): DispatchResult {
println("Отправка команды: ${command.id}")
// renewLock() может вызываться для продления блокировки при длительных задачах
return DispatchResult(status = DispatchStatus.SENT)
}
}
// 2. Инициализация сервиса с реализацией БД и блокировок
val queueService = QueueService(
storage = myStoragePortImpl,
lockPort = myLeaseLockPortImpl,
handler = commandHandler,
backoffPolicy = DefaultBackoffPolicy(),
ownerId = "node-1"
)
// 3. Запуск обработки пакета команд
queueService.processBatch(cashboxId = "cashbox-123", lane = QueueLane.OFFLINE, limit = 10)Библиотека определяет абстрактные порты предметной области для долговременного хранения (QueueStoragePort) и взаимного исключения параллельного выполнения (LeaseLockPort). Конкретные реализации (например, Room на Android, CoreData в iOS или JDBC/Redis на сервере) должны быть предоставлены вызывающим приложением.