diff --git a/consumer/build.gradle.kts b/consumer/build.gradle.kts new file mode 100644 index 0000000..4137b56 --- /dev/null +++ b/consumer/build.gradle.kts @@ -0,0 +1,54 @@ +plugins { + kotlin("jvm") + id("com.google.protobuf") version "0.9.4" +} + +group = "dev.usbharu" +version = "0.0.1" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation("org.jetbrains.kotlin:kotlin-test") + implementation("io.grpc:grpc-kotlin-stub:1.4.1") + implementation("io.grpc:grpc-protobuf:1.61.1") + implementation("com.google.protobuf:protobuf-kotlin:3.25.3") + implementation("io.grpc:grpc-netty:1.61.1") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") + implementation(project(":common")) + protobuf(files(project(":broker").dependencyProject.projectDir.toString() + "/src/main/proto")) +} + +tasks.test { + useJUnitPlatform() +} +kotlin { + jvmToolchain(17) +} + +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:3.25.3" + } + plugins { + create("grpc") { + artifact = "io.grpc:protoc-gen-grpc-java:1.61.1" + } + create("grpckt") { + artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar" + } + } + generateProtoTasks { + all().forEach { + it.plugins { + create("grpc") + create("grpckt") + } + it.builtins { + create("kotlin") + } + } + } +} \ No newline at end of file diff --git a/consumer/src/main/kotlin/Main.kt b/consumer/src/main/kotlin/Main.kt new file mode 100644 index 0000000..3fa8f95 --- /dev/null +++ b/consumer/src/main/kotlin/Main.kt @@ -0,0 +1,36 @@ +package dev.usbharu + +import dev.usbharu.owl.AssignmentTaskServiceGrpcKt +import dev.usbharu.owl.readyRequest +import io.grpc.ManagedChannelBuilder +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.isActive +import kotlinx.coroutines.withContext + +suspend fun main() { + withContext(Dispatchers.Default) { + var isReady = true + AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub( + ManagedChannelBuilder.forAddress( + "localhost", 50051 + ).build() + ).ready(flow { + while (isActive) { + if (isReady) { + emit(readyRequest { + this.consumerId + }) + } + delay(500) + } + }).onEach { + + }.collect() + + + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index f447b5a..87d7071 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,3 +10,4 @@ include("broker:broker-mongodb") findProject(":broker:broker-mongodb")?.name = "broker-mongodb" include("producer:default") findProject(":producer:default")?.name = "default" +include("consumer")