|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.IO; |
4 | | -using System.Reflection; |
5 | | -using Akka.Actor; |
6 | | -using AkkaDotBootApi.Actor; |
7 | | -using AkkaDotModule.ActorSample; |
8 | | -using AkkaDotModule.ActorUtils; |
| 1 | +using Akka.Actor; |
| 2 | +using AkkaDotBootApi.Test; |
9 | 3 | using AkkaDotModule.Config; |
10 | 4 | using AkkaDotModule.Kafka; |
11 | | -using AkkaDotModule.Models; |
12 | 5 | using Microsoft.AspNetCore.Builder; |
13 | 6 | using Microsoft.AspNetCore.Hosting; |
14 | 7 | using Microsoft.Extensions.Configuration; |
15 | 8 | using Microsoft.Extensions.DependencyInjection; |
16 | 9 | using Microsoft.Extensions.Hosting; |
17 | 10 | using Microsoft.OpenApi.Models; |
| 11 | +using System; |
| 12 | +using System.IO; |
| 13 | +using System.Reflection; |
18 | 14 | using IApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime; |
19 | 15 |
|
20 | 16 | namespace AkkaDotBootApi |
@@ -131,56 +127,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplica |
131 | 127 |
|
132 | 128 | lifetime.ApplicationStarted.Register(() => |
133 | 129 | { |
134 | | - // HelloActor 기본액터 |
135 | | - AkkaLoad.RegisterActor("helloActor" /*AkkaLoad가 인식하는 유니크명*/, |
136 | | - actorSystem.ActorOf(Props.Create(() => new HelloActor("webnori")), "helloActor" /*AKKA가 인식하는 Path명*/ |
137 | | - )); |
138 | | - |
139 | | - var helloActor = actorSystem.ActorSelection("user/helloActor"); |
140 | | - var helloActor2 = AkkaLoad.ActorSelect("helloActor"); |
141 | | - |
142 | | - helloActor.Tell("hello"); |
143 | | - helloActor2.Tell("hello"); |
144 | | - |
145 | | - |
146 | | - // 밸브 Work : 초당 작업량을 조절 |
147 | | - int timeSec = 1; |
148 | | - int elemntPerSec = 5; |
149 | | - var throttleWork = AkkaLoad.RegisterActor("throttleWork", |
150 | | - actorSystem.ActorOf(Props.Create(() => new ThrottleWork(elemntPerSec, timeSec)), "throttleWork")); |
151 | | - |
152 | | - // 실제 Work : 밸브에 방출되는 Task를 개별로 처리 |
153 | | - var worker = AkkaLoad.RegisterActor("worker", actorSystem.ActorOf(Props.Create<WorkActor>(), "worker")); |
154 | | - |
155 | | - // 배브의 작업자를 지정 |
156 | | - throttleWork.Tell(new SetTarget(worker)); |
157 | | - |
158 | | - // KAFKA 셋팅 |
159 | | - // 각 System은 싱글톤이기때문에 DI를 통해 Controller에서 참조획득가능 |
160 | | - var consumerSystem = app.ApplicationServices.GetService<ConsumerSystem>(); |
161 | | - var producerSystem = app.ApplicationServices.GetService<ProducerSystem>(); |
162 | | - |
163 | | - //소비자 : 복수개의 소비자 생성가능 |
164 | | - consumerSystem.Start(new ConsumerAkkaOption() |
165 | | - { |
166 | | - KafkaGroupId = "testGroup", |
167 | | - KafkaUrl = "kafka:9092", |
168 | | - RelayActor = null, //소비되는 메시지가 지정 액터로 전달되기때문에,처리기는 액터로 구현 |
169 | | - Topics = "akka100" |
170 | | - }); |
171 | | - |
172 | | - //생산자 : 복수개의 생산자 생성가능 |
173 | | - producerSystem.Start(new ProducerAkkaOption() |
174 | | - { |
175 | | - KafkaUrl = "kafka:9092", |
176 | | - ProducerName = "producer1" |
177 | | - }); |
178 | | - |
179 | | - List<string> messages = new List<string>(); |
180 | | - //보너스 : 생산의 속도를 조절할수 있습니다. |
181 | | - int tps = 10; |
182 | | - producerSystem.SinkMessage("producer1", "akka100", messages, tps); |
183 | | - |
| 130 | + TestAkka.Run(app, actorSystem); |
184 | 131 | }); |
185 | 132 | } |
186 | 133 | } |
|
0 commit comments