【发布时间】:2014-12-16 14:53:19
【问题描述】:
出于某种原因,QUEUE_A 并不总是有 1 个交换 - 有时它有 0,除非我在测试中添加一个 Thread.sleep(100)。我猜 whenCompleted/whenDone 实际上说它已经完成时并没有完全完成。如何验证它是否已完全完成?
multicast().parallelProcessing().to(QUEUE_A, QUEUE_B, QUEUE_C, QUEUE_D)
和测试:
@Test
public void test() {
NotifyBuilder notify = new NotifyBuilder(context)
.from(QUEUE_INCOMING)
.whenCompleted(1)
.create();
template.sendBody(QUEUE_INCOMING, streamToString(loadResourceAsStream("/data/TestData.xml")));
boolean matches = notify.matches(4, SECONDS);
assertTrue("Notify failed", matches);
Thread.sleep(100); //Without this, it fails
verifyEndpoints(1, context, QUEUE_A, QUEUE_B, QUEUE_C, QUEUE_D);
}
public static void verifyEndpoints(int expectedSize, ModelCamelContext context, String... endpoints) {
for (String endpoint : endpoints) {
BrowsableEndpoint be = context.getEndpoint(endpoint, BrowsableEndpoint.class);
assertThat(String.format("Endpoint exchanges '%s' has wrong size", endpoint), be.getExchanges(), hasSize(expectedSize));
}
}
还有端点 bean,在测试时使用 ActiveMQ,但在 prod 中将使用 WebSphere MQ:
<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false" />
</bean>
</property>
</bean>
【问题讨论】:
-
QUEUE_A, ... 是什么样的端点?
-
它们是“wmq:queues:
”。我在第一篇文章中添加了 wmq bean 设置
标签: apache-camel