【问题标题】:Apache Camel Multicast notifyBuilder failsApache Camel 多播 notifyBuilder 失败
【发布时间】: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


【解决方案1】:

问题是您在向 WMQ 发送消息后尽快浏览它,因此取决于代理实现和时间等,在使用 JMS 浏览 api 时您可能看不到最后的消息。

因此,当您稍等片刻时,它似乎可以修复。

【讨论】:

  • 有什么比睡觉更好的解决方案?
  • 当有一个 NotifyBuilder 等待带有窃听的路由时,我实际上遇到了同样的问题。它在窃听返回完成时完成,但整个路由尚未完成。在这种情况下,我可以将 wereSentTo(q) 添加到我正在等待的队列中。但是在多播版本中,我为每个多播队列使用了多个 wereSentTo(),但这不起作用。我实际上没有让 .whenDone(1).wereSentTo(QUEUE_A).wereSentTo(QUEUE_B).create() 工作。可能是一个错误?
猜你喜欢
  • 1970-01-01
  • 2014-08-07
  • 1970-01-01
  • 2023-03-10
  • 2020-09-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多