consumer #2

Merged
usbharu merged 10 commits from consumer into master 2024-04-30 09:26:10 +00:00
1 changed files with 22 additions and 5 deletions
Showing only changes of commit cb1fea975e - Show all commits

View File

@ -17,29 +17,46 @@
package dev.usbharu.owl.consumer package dev.usbharu.owl.consumer
import dev.usbharu.dev.usbharu.owl.consumer.ConsumerConfig import dev.usbharu.dev.usbharu.owl.consumer.ConsumerConfig
import dev.usbharu.dev.usbharu.owl.consumer.TaskRunner
import dev.usbharu.owl.AssignmentTaskServiceGrpcKt import dev.usbharu.owl.AssignmentTaskServiceGrpcKt
import dev.usbharu.owl.SubscribeTaskServiceGrpcKt import dev.usbharu.owl.SubscribeTaskServiceGrpcKt
import dev.usbharu.owl.TaskResultServiceGrpcKt import dev.usbharu.owl.TaskResultServiceGrpcKt
import dev.usbharu.owl.common.property.CustomPropertySerializerFactory import dev.usbharu.owl.common.property.CustomPropertySerializerFactory
import io.grpc.ManagedChannelBuilder import io.grpc.ManagedChannelBuilder
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.util.*
fun main() { fun main() {
val consumerConfig = ConsumerConfig(20, "localhost", 50051) val consumerConfig = ConsumerConfig(20, "localhost", 50051)
val channel = ManagedChannelBuilder.forAddress(consumerConfig.address, consumerConfig.port).usePlaintext().build() val channel = ManagedChannelBuilder.forAddress(consumerConfig.address, consumerConfig.port).usePlaintext().build()
val subscribeTaskServiceCoroutineStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel) val subscribeStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel)
val assignmentTaskServiceCoroutineStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel) val assignmentTaskStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel)
val taskResultServiceCoroutineStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel) val taskResultStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel)
val customPropertySerializerFactory = CustomPropertySerializerFactory(emptySet()) val customPropertySerializerFactory = CustomPropertySerializerFactory(emptySet())
val taskRunnerMap = ServiceLoader
.load(TaskRunner::class.java)
.associateBy { it::class.qualifiedName!! }
.filterNot { it.key.isBlank() }
val consumer = Consumer( val consumer = Consumer(
subscribeTaskServiceCoroutineStub, assignmentTaskServiceCoroutineStub, taskResultServiceCoroutineStub, subscribeStub,
emptyMap(), customPropertySerializerFactory, consumerConfig assignmentTaskStub,
taskResultStub,
taskRunnerMap,
customPropertySerializerFactory,
consumerConfig
) )
runBlocking { runBlocking {
consumer.init("consumer", "consumer-1")
consumer.start() consumer.start()
Runtime.getRuntime().addShutdownHook(Thread {
consumer.stop()
})
} }
} }