2014-10-01 7 views
1

저는 top-shelf와 rebus를 사용하여 "다중 근로자"애플리케이션을 작성하고 있습니다.하나의 리버스 프로세스에서 다중 입력 대기열

내 아이디어는 MyWorker1Namespace - MyWorker1Namespace.Messages, MyWorker2Namespace - MyWorker2Namespace.Messages 패턴을 사용하는 것입니다.

여러 프로세스에 걸쳐 있지 않고 응용 프로그램을 실행하고 싶습니다. 대신에 moultiple 입력 대기열로 응용 프로그램을 구성하여 필요할 경우 여러 프로세스로 분할 할 준비가 필요합니다.

Rebus를 사용하여 하나의 응용 프로그램에서 다중 입력 대기열과 다중 작업자 스레드를 선언 할 수있는 방법이 있습니까?

나는 구성이 같은 것을해야 추측 다음 수수께끼가 XML은 한 종류의 버스 인스턴스 당 처리 시나리오에 최적화되어있는 app.config 때문에

<rebus inputQueue="MyWorker1Namespace.input" errorQueue="MyWorker1Namespace.error" workers="1" maxRetries="5"> </rebus> 
<rebus inputQueue="MyWorker2Namespace.input" errorQueue="MyWorker2Namespace.error" workers="1" maxRetries="5"> </rebus> 
... 

답변

7

, 여러 버스 을 구성 할 수 없습니다 완전히을 XML 형식으로 처리하지만 동일한 프로세스 내에서 여러 버스 인스턴스를 시작할 수 없게합니다.

나는 종종 이렇게했습니다. 물리적으로 분리 된 배포 비용을 들이지 않고도 여러 논리적 끝점을 호스팅하려는 Azure 작업자 역할에서, 그리고 때로는 Topshelf에서 호스팅하는 Windows Services에서도 수행했습니다.

일반적으로, 내 app.config에 다음과 같은 XML과 끝 :

<rebus workers="1"> 
    <add messages="SomeAssembly.Messages" endpoint="someEndpoint.input"/> 
    <add messages="AnotherAssembly.Messages" endpoint="anotherEndpoint.input"/> 
</rebus> 

이렇게 나를 한번에 버스 당 노동자와 엔드 포인트 매핑의 기본 개수를 구성 할 수 있습니다. 그런 다음 응용 프로그램이 시작되면 응용 프로그램 수명 기간 동안 버스 당 IoC 컨테이너가 유지됩니다. Windsor를 사용하면 대개 대기열 이름에 대한 매개 변수가있는 일반 버스 설치 프로그램으로 끝납니다. Windsor를 구성 할 수 있습니다 이와 같은 (A 윈저기구 임) RebusInstaller가 근본적으로 단지 용기, 예를 들면 오른쪽으로 큐 이름 버스두고

var containers = new List<IWindsorContainer> { 
    new WindsorContainer() 
     // always handlers first 
     .Install(FromAssembly.Containing<SomeEndpoint.SomeHandler>()) 

     // and then the bus, which gets started at this point 
     .Install(new RebusInstaller("someEndpoint.input", "error")) 

     // and then e.g. background timers and other "living things" 
     .Install(new PeriodicTimersInstannce()), 

    new WindsorContainer() 
     .Install(FromAssembly.Containing<AnotherEndpoint.AnotherHandler>()) 
     .Install(new RebusInstaller("anotherEndpoint.input", "error")) 
}; 

// and then remember to dispose each container when shutting down the process 

이런 식으로 :

Configure.With(new WindsorContainerAdapter(container)) 
    .Transport(t => t.UseMsmq(_inputQueueName, _errorQueueName)) 
    .(...) etc 
    .CreateBus().Start(); 

저는 각 IoC 컨테이너 인스턴스가 논리적으로 독립적 인 응용 프로그램으로 작동한다는 생각을 좋아합니다. 이렇게하면 나중에 예를 들어 원하는 경우 시간을 따로 나누는 것이 쉬울 것입니다. 엔드 포인트를 독립적으로 배치 할 수 있어야합니다.

나는 이것이 당신에게 영감을 줄 수 있기를 바랍니다. 더 많은 포인터가 필요한지 물어보십시오.

+0

흥미로운 답변을 주셔서 감사합니다. 나는 일반적으로 Ninject를 IoC로 사용한다. 각 작업자에게 전용 버스를 삽입하기 위해 문맥 바인딩이있는 단일 컨테이너를 사용하여 비슷한 접근법을 시도 할 것입니다. – Ganto