2012-08-10 2 views
3

각 메시지가 소비자 또는 무용담에 부딪치기 전에 검사하고 싶습니다. 나는 IInboundMessageInterceptor를 원한다고 생각하지만, 커스텀 인터페이스를 삽입하는 쉬운 방법을 볼 수 없다. MT에서 메시지 차단을 어떻게 수행합니까? 그리고/또는 어떻게 사용자 정의 IInboundMessageInterceptor로 버스를 구성 할 수 있습니까?MassTransit에서 메시지 차단을 어떻게 할 수 있습니까?

답변

5

다음을 수행 할 수 있습니다. 귀하의 인터셉터는 그런 다음 이렇게

internal class MyInboundInterceptor : IInboundMessageInterceptor 
{ 
    public MyInboundInterceptor(ServiceBus bus) 
    { 

    } 

    public void PreDispatch(IConsumeContext context) 
    { 
     IConsumeContext<AwesomeCommand> typedContext; 
     if (context.TryGetContext(out typedContext)) 
     { 
      // Do SOmething with typedContext.Message 
     } 
    } 

    public void PostDispatch(IConsumeContext context) 
    { 
    } 
} 
+0

매우 강력한 잠재력처럼 인터셉터를 작성할 수 IInboundMessageInterceptor

Bus.Initialize(sbc => { // ... Initialise Settings ... var busConfiguratorr = new PostCreateBusBuilderConfigurator(bus => { var interceptorConfigurator = new InboundMessageInterceptorConfigurator(bus.InboundPipeline); interceptorConfigurator.Create(new MyIncomingInterceptor(bus)); }); sbc.AddBusConfigurator(busConfiguratorr); }); 

구현해야합니다! – slimflem

+1

친애하는 아담, 나는 하나 이상의 메시지를 가로 챌 수 있으므로 아래와 같이 여러 개의 IConsumeContext를 정의해야합니다. IConsumeContext typedContext; IConsumeContext typedContext; IConsumeContext typedContext; 제발 도와주세요 .. – faisale

관련 문제