feat: wip consumer
This commit is contained in:
		
							parent
							
								
									1c576f9463
								
							
						
					
					
						commit
						6a3551f3b4
					
				|  | @ -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") | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -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() | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | @ -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") | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue