All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.caesarealabs.loggy.jvm.LoggyRpcServer.kt Maven / Gradle / Ivy

package com.caesarealabs.loggy.jvm

import com.caesarealabs.loggy.database.LoggyServiceImpl
import com.caesarealabs.loggy.shared.LoggyService
import com.caesarealabs.rpc4k.generated.rpc4k
import com.caesarealabs.rpc4k.runtime.jvm.user.components.ApiGatewayMessageLauncher
import com.caesarealabs.rpc4k.runtime.jvm.user.components.mongo.MongoDb
import com.caesarealabs.rpc4k.runtime.jvm.user.components.mongo.MongodbEventManager
import com.caesarealabs.rpc4k.runtime.user.setupServer


public fun createLoggyRpc() = LoggyService.rpc4k.setupServer(
    messageLauncher = ApiGatewayMessageLauncher(
        region = "eu-central-1",
        websocketConnectionUrl = "wss://qmrujo9qfg.execute-api.eu-central-1.amazonaws.com/production/"
    ),
    eventManager = MongodbEventManager(LoggyMongoDbAtlas, databaseName = "loggy-events")
) { LoggyServiceImpl(it, database = LoggyMongoDbDatabase(LoggyMongoDbAtlas)) }

 fun mongoDbConnectionUrl() = getResource("/mongodb_connection_string.txt") ?: error(
    "Missing mongodb connection string in environment, " +
        "LOGGY_MONGO_CONNECTION_STRING has to be set to connect to release database."
)

/**
 * Utility for easily fetching any resources from the resources dir
 */
@Suppress("NewApi")
private fun getResource(path: String): String? {
    return LoggyMongodb::class.java.getResourceAsStream(path)?.use { it.readAllBytes() }?.decodeToString()
}
private val LoggyMongoDbAtlas = MongoDb.Atlas { mongoDbConnectionUrl() }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy