- try making a factorio mod portal api client, for auto releasing
- make webmapTileDir a configurable variable
This commit is contained in:
parent
ec1f1bc200
commit
7141d7e5f7
16 changed files with 287 additions and 34 deletions
|
|
@ -40,14 +40,9 @@ dependencies {
|
|||
implementation("com.sksamuel.scrimage:scrimage-core:4.0.24")
|
||||
|
||||
val kotkaVersion = "v0.0.12"
|
||||
// val kotkaVersion = "store-iterators-SNAPSHOT"
|
||||
implementation("com.github.adamko-dev.kotka-streams:kotka-streams:$kotkaVersion") {
|
||||
isChanging = true
|
||||
}
|
||||
// val kotkaVersion = "main-SNAPSHOT"
|
||||
// implementation("dev.adamko.kotka:kotka-streams:$kotkaVersion") {
|
||||
// isChanging = true
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@ import org.apache.kafka.clients.admin.CreateTopicsResult
|
|||
import org.apache.kafka.clients.admin.NewTopic
|
||||
import org.apache.kafka.clients.admin.TopicListing
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
//fun main() {
|
||||
// KafkaAdmin.createKafkatorioTopics()
|
||||
//}
|
||||
|
||||
object KafkaAdmin {
|
||||
object KafkatorioKafkaAdmin {
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
private val kafkaAdmin: Admin =
|
||||
Admin.create(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import dev.adamko.kafkatorio.events.schema.FactorioEvent
|
|||
import dev.adamko.kafkatorio.events.schema.FactorioObjectData
|
||||
import dev.adamko.kafkatorio.events.schema.FactorioPrototypes
|
||||
import dev.adamko.kafkatorio.events.schema.KafkatorioPacket
|
||||
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
|
||||
import dev.adamko.kafkatorio.processor.serdes.jsonMapper
|
||||
import dev.adamko.kafkatorio.processor.serdes.kxsBinary
|
||||
import dev.adamko.kafkatorio.processor.topology.FactorioServerId
|
||||
|
|
@ -36,8 +37,9 @@ import org.apache.kafka.streams.kstream.KStream
|
|||
import org.apache.kafka.streams.kstream.KTable
|
||||
|
||||
|
||||
class KafkatorioTopology(
|
||||
internal class KafkatorioTopology(
|
||||
private val websocketServer: WebsocketServer,
|
||||
private val appProps: ApplicationProperties = ApplicationProperties(),
|
||||
) : CoroutineScope {
|
||||
|
||||
override val coroutineContext: CoroutineContext =
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package dev.adamko.kafkatorio.processor.config
|
||||
|
||||
import dev.adamko.kafkatorio.processor.config.PortVal.Companion.portVal
|
||||
import java.nio.file.Path
|
||||
import java.time.Clock
|
||||
import java.util.Properties
|
||||
import kotlin.io.path.Path
|
||||
import org.http4k.cloudnative.env.Environment
|
||||
import org.http4k.cloudnative.env.EnvironmentKey
|
||||
import org.http4k.lens.nonEmptyString
|
||||
|
|
@ -15,19 +17,21 @@ import org.http4k.lens.nonEmptyString
|
|||
* # 3. A resources-dir yaml file
|
||||
*
|
||||
*/
|
||||
class ApplicationProperties(
|
||||
internal class ApplicationProperties(
|
||||
vararg environments: Environment = arrayOf(
|
||||
Environment.env(),
|
||||
Environment.fromEnvVarPath(),
|
||||
Environment.fromResourcesFile(".secret.config.yml")
|
||||
)
|
||||
) {
|
||||
|
||||
|
||||
private val appProps: Environment =
|
||||
environments.reduce { acc, environment -> acc.overrides(environment) }
|
||||
|
||||
|
||||
fun clock(): Clock = Clock.systemUTC()
|
||||
|
||||
//<editor-fold desc="Server properties">
|
||||
|
||||
/**
|
||||
* The port of the server
|
||||
|
|
@ -37,10 +41,6 @@ class ApplicationProperties(
|
|||
val serverPort: PortVal
|
||||
get() = EnvironmentKey.portVal().defaulted("PORT", PortVal.DEFAULT)[appProps]
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
|
||||
//<editor-fold desc="Kafka properties">
|
||||
|
||||
val kafkaConfig: Properties
|
||||
get() = EnvironmentKey
|
||||
|
|
@ -54,6 +54,11 @@ class ApplicationProperties(
|
|||
}
|
||||
.required("kafka.config")[appProps]
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
val webmapTileDir: Path
|
||||
get() = EnvironmentKey
|
||||
.nonEmptyString()
|
||||
.map(::Path)
|
||||
.required("tileServer.webmapTileDir")[appProps]
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ import org.http4k.lens.Lens
|
|||
*
|
||||
* (An improved version of [Environment.fromResource])
|
||||
*/
|
||||
internal fun Environment.Companion.fromResourcesFile(
|
||||
fun Environment.Companion.fromResourcesFile(
|
||||
resource: String,
|
||||
default: Environment = EMPTY
|
||||
) =
|
||||
try {
|
||||
): Environment {
|
||||
return try {
|
||||
val file =
|
||||
this::class.java
|
||||
.getResource("/${resource.removePrefix("/")}")
|
||||
|
|
@ -27,6 +27,7 @@ internal fun Environment.Companion.fromResourcesFile(
|
|||
} catch (e: FileNotFoundException) {
|
||||
default
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try fetching a properties file the location provided by the
|
||||
|
|
@ -35,7 +36,7 @@ internal fun Environment.Companion.fromResourcesFile(
|
|||
*
|
||||
* If it does not exist, return [default].
|
||||
*/
|
||||
internal fun Environment.Companion.fromEnvVarPath(
|
||||
fun Environment.Companion.fromEnvVarPath(
|
||||
location: Lens<Environment, File?> = Lenses.APPLICATION_PROPERTIES_FILE_PATH,
|
||||
default: Environment = EMPTY,
|
||||
): Environment {
|
||||
|
|
@ -65,7 +66,7 @@ internal fun Environment.Companion.fromFile(
|
|||
}
|
||||
|
||||
/** The same as [Environment.ENV], but refreshes on each invocation (which is useful for testing). */
|
||||
internal fun Environment.Companion.env(): Environment =
|
||||
fun Environment.Companion.env(): Environment =
|
||||
MapEnvironment.from(System.getenv().toProperties())
|
||||
|
||||
/** The same as [Environment.JVM_PROPERTIES], but refreshes on each invocation (which is useful for testing). */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.adamko.kafkatorio.processor
|
||||
|
||||
|
||||
import dev.adamko.kafkatorio.admin.KafkaAdmin
|
||||
import dev.adamko.kafkatorio.admin.KafkatorioKafkaAdmin
|
||||
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
|
||||
import dev.adamko.kafkatorio.processor.tileserver.WebMapTileServer
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
|
@ -10,12 +10,12 @@ import org.http4k.server.Undertow
|
|||
import org.http4k.server.asServer
|
||||
|
||||
|
||||
val appProps = ApplicationProperties()
|
||||
//private val appProps = ApplicationProperties()
|
||||
|
||||
|
||||
fun main(): Unit = runBlocking {
|
||||
|
||||
KafkaAdmin.createKafkatorioTopics()
|
||||
KafkatorioKafkaAdmin.createKafkatorioTopics()
|
||||
|
||||
val wsServer = WebsocketServer()
|
||||
val tileServer = WebMapTileServer()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.adamko.kafkatorio.processor.tileserver
|
||||
|
||||
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
|
||||
import kotlin.io.path.absolutePathString
|
||||
import org.http4k.core.HttpHandler
|
||||
import org.http4k.core.then
|
||||
import org.http4k.filter.CachingFilters
|
||||
|
|
@ -9,17 +11,13 @@ import org.http4k.routing.bind
|
|||
import org.http4k.routing.routes
|
||||
import org.http4k.routing.static
|
||||
|
||||
class WebMapTileServer {
|
||||
internal class WebMapTileServer(
|
||||
appProps: ApplicationProperties = ApplicationProperties()
|
||||
) {
|
||||
|
||||
private val routes: RoutingHttpHandler = routes(
|
||||
"/tiles" bind CachingFilters.Response.NoCache()
|
||||
.then(
|
||||
static(
|
||||
ResourceLoader.Directory(
|
||||
"""D:\Users\Adam\Projects\games\kafkatorio\modules\events-server\src\main\resources\kafkatorio-web-map\"""
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(static(ResourceLoader.Directory(appProps.webmapTileDir.absolutePathString())))
|
||||
)
|
||||
|
||||
fun build(): HttpHandler {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue