Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

AkkaSystem을 사용하기 위한 최초 코드작성

Code Block
languagec#
themeDJango
titleProgram.cs
linenumberstrue
using System;
using Akka.Actor;
using Akka.Routing;

namespace ServiceA
{
    class Program
    {
        static void Main(string[] args)
        {
            ConsoleKeyInfo cki;
            Console.CancelKeyPress += new ConsoleCancelEventHandler(myHandler);            
            using (ActorSystem system = ActorSystem.Create("ServiceA"))
            {
				//Actor의 시스템 준비 완료
             //Actor의 시스템 준비 완료

                while (true)
                {                    
                    // 메인 어플리케이션 종료방지를 위한코드 ( ctrl+x 종료 )
                    cki = Console.ReadKey(true);
                    if (cki.Key == ConsoleKey.X) break;
                }
            }
        }

        protected static void myHandler(object sender, ConsoleCancelEventArgs args)
        {
            args.Cancel = true;
        }
    }
}






App.config

.net의 어플리케이션 설정과 호환가능:  특이한 형태의 설정으로  JAVA와 설정방식호환  

Code Block
themeDJango
title8001번 포트를 서비스하는 AKKA System 설정
linenumberstrue
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
      <section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <akka>  <akka>
  
    <hocon>
        <![CDATA[     
  
          akka {
              actor {            
  
              provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
                  deployment {}
                    /some-group {
                      router = broadcast-group
                      routees.paths = [
                        "akka.tcp://ServiceB@127.0.0.1:8002/user/b1",
                        "akka.tcp://ServiceB@127.0.0.1:8002/user/b2", 
                        "akka.tcp://ServiceB@127.0.0.1:8002/user/b3"]
                    }                    
              }
            }
            remote {
            remote {
              log-remote-lifecycle-events = DEBUG
                log-received-messages = on
               
                helios.tcp {
                    port = 8001 #bound to a specific port
                    hostname = 127.0.0.1
                }
              }           
  
          }         
  
      ]]>
      </hocon>
    </akka>
</configuration>

기본적인 설정 방법이며

서비스포트 (8001) , 라우터 정의및 로그등 기본적인 설정 방법입니다.

확장된 설정법(클러스터구성) 은 실습코드에서 다시 정리예정

...


실행확인

[WARNING][2017-09-01 오전 7:34:45][Thread 0018][ActorSystem(system)] NewtonSoftJsonSerializer has been detected as a default serializer. It will be obsoleted in Akka.NET starting from version 1.5 in the favor of Hyperion (for more info visit: http://getakka.net/docs/Serialization#how-to-setup-hyperion-as-default-serializer ). If you want to suppress this message set HOCON `akka.suppress-json-serializer-warning` config flag to on.

...