diff --git a/hideout-core/build.gradle.kts b/hideout-core/build.gradle.kts index ae7b5128..ca8e9cf8 100644 --- a/hideout-core/build.gradle.kts +++ b/hideout-core/build.gradle.kts @@ -191,6 +191,7 @@ dependencies { implementation(libs.bundles.apache.tika) implementation(libs.bundles.openapi) implementation(libs.bundles.owl.producer) + implementation(libs.bundles.owl.broker) implementation(libs.bundles.spring.boot.oauth2) implementation(libs.bundles.spring.boot.data.mongodb) implementation(libs.bundles.spring.boot.data.mongodb) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/OwlConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/OwlConfig.kt index 24acde80..51d3be21 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/OwlConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/OwlConfig.kt @@ -16,20 +16,23 @@ package dev.usbharu.hideout.application.config +import dev.usbharu.owl.broker.ModuleContext import dev.usbharu.owl.common.retry.RetryPolicyFactory import dev.usbharu.owl.producer.api.OWL import dev.usbharu.owl.producer.api.OwlProducer import dev.usbharu.owl.producer.defaultimpl.DEFAULT import dev.usbharu.owl.producer.embedded.EMBEDDED import dev.usbharu.owl.producer.embedded.EMBEDDED_GRPC +import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import java.util.* @Configuration class OwlConfig(private val producerConfig: ProducerConfig) { @Bean - fun producer(retryPolicyFactory: RetryPolicyFactory? = null): OwlProducer { + fun producer(@Autowired(required = false) retryPolicyFactory: RetryPolicyFactory? = null): OwlProducer { return when (producerConfig.mode) { ProducerMode.EMBEDDED -> { OWL(EMBEDDED) { @@ -39,6 +42,10 @@ class OwlConfig(private val producerConfig: ProducerConfig) { if (producerConfig.port != null) { this.port = producerConfig.port.toString() } + val moduleContext = ServiceLoader.load(ModuleContext::class.java).firstOrNull() + if (moduleContext != null) { + this.moduleContext = moduleContext + } } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt new file mode 100644 index 00000000..06f74c44 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.application.external + +import dev.usbharu.owl.common.task.TaskDefinition +import dev.usbharu.owl.producer.api.OwlProducer +import kotlinx.coroutines.runBlocking +import org.springframework.boot.ApplicationArguments +import org.springframework.boot.ApplicationRunner +import org.springframework.stereotype.Component + +@Component +class OwlProducerRunner(private val owlProducer: OwlProducer, private val taskDefinitions: List>) : + ApplicationRunner { + override fun run(args: ApplicationArguments?) { + runBlocking { + owlProducer.start() + taskDefinitions.forEach { taskDefinition -> owlProducer.registerTask(taskDefinition) } + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt index a5893c71..de3f4332 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverAcceptTask( val accept: Accept, @@ -28,6 +29,7 @@ data class DeliverAcceptTask( val signer: Long, ) : Task() +@Component data object DeliverAcceptTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt index 1aabefc3..66a7bce1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverCreateTask( val create: Create, @@ -28,6 +29,7 @@ data class DeliverCreateTask( val actor: String, ) : Task() +@Component data object DeliverCreateTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt index 801a917f..b4b55f51 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverDeleteTask( val delete: Delete, @@ -28,6 +29,7 @@ data class DeliverDeleteTask( val signer: Long, ) : Task() +@Component data object DeliverDeleteTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt index e2f8001a..cd122db7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverReactionTask( val actor: String, @@ -28,6 +29,7 @@ data class DeliverReactionTask( val inbox: String, ) : Task() +@Component data object DeliverReactionTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt index e675409c..b76e9f5e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverRejectTask( val reject: Reject, @@ -28,6 +29,7 @@ data class DeliverRejectTask( val signer: Long, ) : Task() +@Component data object DeliverRejectTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt index f0ae462f..60ca28ba 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class DeliverUndoTask( val undo: Undo, @@ -28,6 +29,7 @@ data class DeliverUndoTask( val signer: Long, ) : Task() +@Component data object DeliverUndoTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt index e5f0fc95..9206cc2b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt @@ -22,6 +22,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class InboxTask( val json: String, @@ -30,6 +31,7 @@ data class InboxTask( val headers: Map>, ) : Task() +@Component data object InboxTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt index 7dc1aac5..d212896b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt @@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.TaskDefinition +import org.springframework.stereotype.Component data class ReceiveFollowTask( val actor: String, @@ -28,6 +29,7 @@ data class ReceiveFollowTask( val targetActor: String, ) : Task() +@Component data object ReceiveFollowTaskDef : TaskDefinition { override val name: String get() = TODO("Not yet implemented") diff --git a/hideout-core/src/main/resources/application.yml b/hideout-core/src/main/resources/application.yml index 425c64f9..ae863531 100644 --- a/hideout-core/src/main/resources/application.yml +++ b/hideout-core/src/main/resources/application.yml @@ -1,5 +1,5 @@ hideout: - url: "https://test-hideout.usbharu.dev" + url: "https://test-hideout-dev.usbharu.dev" use-mongodb: true owl: producer: diff --git a/libs.versions.toml b/libs.versions.toml index 5af99f9a..ee3e55dd 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -60,6 +60,8 @@ kjon-mongo = { module = "org.drewcarlson:kjob-mongo", version.ref = "kjob" } owl-producer-api = { module = "dev.usbharu:owl-producer-api", version.ref = "owl" } owl-producer-default = { module = "dev.usbharu:owl-producer-default", version.ref = "owl" } owl-producer-embedded = { module = "dev.usbharu:owl-producer-embedded", version.ref = "owl" } +owl-broker = { module = "dev.usbharu:owl-broker", version.ref = "owl" } +owl-broker-mongodb = { module = "dev.usbharu:owl-broker-mongodb", version.ref = "owl" } jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" } jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" } @@ -76,6 +78,7 @@ serialization = ["serialization-core", "serialization-json"] apache-tika = ["apache-tika-core", "apache-tika-parsers"] kjob = ["kjon-core", "kjon-mongo"] owl-producer = ["owl-producer-api", "owl-producer-default", "owl-producer-embedded"] +owl-broker = ["owl-broker", "owl-broker-mongodb"] [plugins]