84.9. 여러Consumers 사용

이 예제에서는 두 개의 소비자를 정의하고 스프링 빈으로 등록합니다.

<!-- define the consumers as spring beans -->
<bean id="consumer1" class="org.apache.camel.spring.example.FooEventConsumer"/>

<bean id="consumer2" class="org.apache.camel.spring.example.AnotherFooEventConsumer"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <!-- define a shared endpoint which the consumers can refer to instead of using url -->
    <endpoint id="foo" uri="disruptor:foo?multipleConsumers=true"/>
</camelContext>

Disruptor foo endpoint에 여러Consumers=true를 지정했기 때문에 두 개 이상의 소비자가 메시지 사본을 pub-sub 스타일 메시지 유형으로 수신할 수 있습니다. 빈이 단위 테스트의 일부이므로 mock 엔드포인트에 메시지를 보낼 수 있지만, @Consume를 사용하여 Disruptor에서 사용할 수 있는 방법을 확인할 수 있습니다.

public class FooEventConsumer {

    @EndpointInject(uri = "mock:result")
    private ProducerTemplate destination;

    @Consume(ref = "foo")
    public void doSomething(String body) {
        destination.sendBody("foo" + body);
    }

}