Page History
...
코드구현
Code Block | ||
---|---|---|
| ||
private val materializer = Materializer.createMaterializer(context.system)
private fun onProcessNumber(command: ProcessNumber): Behavior<GraphCommand> {
context.log.info("Received ProcessNumber command with number: ${command.number} - ${context.self.path().name()}")
Source.single(command.number)
.via(operation)
.buffer(1000, OverflowStrategy.dropHead())
.throttle(10, Duration.ofSeconds(1))
.runWith(Sink.foreach { result -> command.replyTo.tell(ProcessedNumber(result)) }, materializer)
return this
} |
- 초기 셋업과정은 복잡할수 있지만~ 복잡한 성능고려 처리를 직관적이고 심플하게 이용할수 있습니다.
- materializer : stream이 수행되는 실행공간으로 액터의 컨텍스트로부터 획득가능하며 , 액터모델없이 외부에서도 사용가능합니다.
TestCode
Code Block | ||
---|---|---|
| ||
@Test fun testProcessNumberAdd() { val probe: TestProbe<GraphCommand> = testKit.createTestProbe() val graphActor: ActorRef<GraphCommand> = testKit.spawn(GraphActor.create()) graphActor.tell(ProcessNumber(5, probe.ref)) val response = probe.receiveMessage() as ProcessedNumber assertEquals(6, response.result) } |
...