85.9. 使用 multipleConsumers
在这个示例中,我们定义了两个消费者,并将其注册为 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,所以我们可以使这两个或者多个消费者接收自己的消息副本作为 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);
}
}