84.9. multipleConsumers の使用
この例では、2 つのコンシューマーを定義し、Spring Bean として登録しました。
<!-- 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 エンドポイントで multipleConsumers=true を指定したので、これら 2 つ以上のコンシューマーに、一種の pub-sub スタイルメッセージングとしてメッセージの独自のコピーを受信させることができます。Bean は単体テストの一部であるため、メッセージをモックエンドポイントに送信するだけですが、@Consume を使用して Disruptor から消費する方法に注目してください。
public class FooEventConsumer {
@EndpointInject(uri = "mock:result")
private ProducerTemplate destination;
@Consume(ref = "foo")
public void doSomething(String body) {
destination.sendBody("foo" + body);
}
}