consumer #1

Merged
usbharu merged 5 commits from consumer into master 2024-04-03 04:47:45 +00:00
3 changed files with 91 additions and 0 deletions
Showing only changes of commit 6a3551f3b4 - Show all commits

54
consumer/build.gradle.kts Normal file
View File

@ -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")
}
}
}
}

View File

@ -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()
}
}

View File

@ -10,3 +10,4 @@ include("broker:broker-mongodb")
findProject(":broker:broker-mongodb")?.name = "broker-mongodb" findProject(":broker:broker-mongodb")?.name = "broker-mongodb"
include("producer:default") include("producer:default")
findProject(":producer:default")?.name = "default" findProject(":producer:default")?.name = "default"
include("consumer")