Versions Compared

Key

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

...

draw.io Diagram
bordertrue
viewerToolbartrue
fitWindowfalse
diagramNamewokersactor
simpleViewerfalse
width
diagramWidth613
revision2


Wokers구현

expand
Code Block
languagebash
themeEmacs
title라운드로빈설정application.conf
akka {

 
 actor.deployment {


 /workers/router1 {


 router = round-robin-pool


 nr-of-instances =
5
}
}
}
 5
 }
 } 
}

코드의 변경없이 random-pool,balancing-pool 등 

원하는 분배방식을 설정으로 통해 결정할수가 있습니다.


Code Block
languagejava
themeEmacs
@Component
@Scope("prototype")
public class Workers extends AbstractActor {
    private final LoggingAdapter log = Logging
            .getLogger(getContext().system(), "Workers");
    
    @Autowired
    private ApplicationContext context;    
    
    private ActorRef roundrobinpool = null;
        
    @Override public void preStart() {
		log.info("Workers::preStart");
		SpringExtension ext = context.getBean(SpringExtension.class);		


        //application.conf에 설정된 라우터방식으로 작동방식결정됨
		roundrobinpool = getContext().actorOf( FromConfig.getInstance().props( ext.props("testActor") ) , "router1"); //액터설정에 의해 5개의 라우티가 생성됨
	}
	
	@Override
	public Receive createReceive() {
		return receiveBuilder()
		.matchEquals("hi1",s->{  //hi1 메시지를 받으면 라운드로빈처리를함
			log.info("Workers::Received String message: {}", s);
			roundrobinpool.tell(s, getSender() );	// 입력된 잡(hi1)을 라운드 로빈라우터에게 메시지전송				
		})
		.matchAny(o -> log.info("received unknown message"))
		.build();
	}
}

...