22using AkkaDotBootApi . Actor ;
33using AkkaDotModule . ActorSample ;
44using AkkaDotModule . ActorUtils ;
5+ using AkkaDotModule . ActorUtils . Confluent ;
56using AkkaDotModule . Config ;
67using AkkaDotModule . Kafka ;
78using AkkaDotModule . Models ;
9+ using Confluent . Kafka ;
810using Microsoft . AspNetCore . Builder ;
911using Microsoft . Extensions . DependencyInjection ;
1012using System . Collections . Generic ;
@@ -39,7 +41,55 @@ static public void Start(IApplicationBuilder app, ActorSystem actorSystem)
3941 // 배브의 작업자를 지정
4042 throttleWork . Tell ( new SetTarget ( worker ) ) ;
4143
42- // KAFKA 셋팅
44+
45+ // 기호에따라 사용방식이 약간 다른 KAFKA를 선택할수 있습니다.
46+
47+ //##################################################################
48+ //##### Confluent.Kafka를 Akka액터 모드로 연결한 모드로
49+ //##### 보안연결이 지원하기때문에 Saas형태의 Kafka에 보안연결이 가능합니다.
50+ //##### 커스텀한 액터를 생성하여,AkkaStream을 이해하고 직접 연결할수 있을때 유용합니다.
51+ //##################################################################
52+ //ProducerActor
53+
54+ var producerAkkaOption = new ProducerAkkaOption ( )
55+ {
56+ BootstrapServers = "webnori-kafka.servicebus.windows.net:9093" ,
57+ ProducerName = "webnori-kafka" ,
58+ SecuritOption = new KafkaSecurityOption ( )
59+ {
60+ SecurityProtocol = SecurityProtocol . SaslSsl ,
61+ SaslMechanism = SaslMechanism . Plain ,
62+ SaslUsername = "$ConnectionString" ,
63+ SaslPassword = "Endpoint=sb://webnori-kafka.servicebus.windows.net/;SharedAccessKeyName=kafka-client;SharedAccessKey=PfL0qRUm50AXZHRXLiVfnatIRI3OqAh+dT6Owsqrd2M=" ,
64+ SslCaLocation = "./cacert.pem"
65+ }
66+ } ;
67+
68+ string producerActorName = "producerActor" ;
69+
70+ var producerActor = AkkaLoad . RegisterActor ( producerActorName /*AkkaLoad가 인식하는 유니크명*/ ,
71+ actorSystem . ActorOf ( Props . Create ( ( ) =>
72+ new ProducerActor ( producerAkkaOption ) ) ,
73+ producerActorName /*AKKA가 인식하는 Path명*/
74+ ) ) ;
75+
76+ producerActor . Tell ( new BatchData ( )
77+ {
78+ Data = new KafkaTextMessage ( )
79+ {
80+ Topic = "akka100" ,
81+ Message = "testData"
82+ }
83+ } ) ;
84+
85+
86+ //##################################################################
87+ //##### Akka.Streams.Kafka(의존:Confluent.Kafka) 을 사용하는 모드로, Security(SSL)이 아직 지원되지 않습니다.
88+ //##### Private으로 구성된, Kafka Pass 모드일때 사용가능합니다.
89+ //##### AkkaStream.Kafka가 제공하는 스트림을 활용핼때 장점이 있습니다.
90+ //##################################################################
91+
92+ // KAFKA -
4393 // 각 System은 싱글톤이기때문에 DI를 통해 Controller에서 참조획득가능
4494 var consumerSystem = app . ApplicationServices . GetService < ConsumerSystem > ( ) ;
4595 var producerSystem = app . ApplicationServices . GetService < ProducerSystem > ( ) ;
@@ -48,16 +98,16 @@ static public void Start(IApplicationBuilder app, ActorSystem actorSystem)
4898 consumerSystem . Start ( new ConsumerAkkaOption ( )
4999 {
50100 KafkaGroupId = "testGroup" ,
51- KafkaUrl = "kafka:9092" ,
101+ BootstrapServers = "kafka:9092" ,
52102 RelayActor = null , //소비되는 메시지가 지정 액터로 전달되기때문에,처리기는 액터로 구현
53- Topics = "akka100"
103+ Topics = "akka100" ,
54104 } ) ;
55105
56106 //생산자 : 복수개의 생산자 생성가능
57107 producerSystem . Start ( new ProducerAkkaOption ( )
58108 {
59- KafkaUrl = "kafka:9092" ,
60- ProducerName = "producer1"
109+ BootstrapServers = "kafka:9092" ,
110+ ProducerName = "producer1" ,
61111 } ) ;
62112
63113 List < string > messages = new List < string > ( ) ;
@@ -69,7 +119,6 @@ static public void Start(IApplicationBuilder app, ActorSystem actorSystem)
69119 //보너스 : 생산의 속도를 조절할수 있습니다.
70120 int tps = 10 ;
71121 producerSystem . SinkMessage ( "producer1" , "akka100" , messages , tps ) ;
72-
73122 }
74123 }
75124}
0 commit comments