计时器监视器从骆驼路线生成大量消息

Timer monitor generating bulk of messages from camel route

我有两条骆驼路线使用 timer:monitor 发送固定消息(心跳)。这将依次从生产者处理器发送到两个端点。当消息未被消费者使用时,同一消息将从生产者处退出 3 次。成功消费后,定时器应该发送下一条消息。但对我来说,它会发送在生产者中重试消息时在计时器监视器中挂起的所有消息。

我在我的路由构建器中使用了如下定时器监控路由

for (final EndpointInfo endpointInfo : endpointInfos) {
            final String uri = SIA_ENDPOINT_PREFIX + endpointInfo.getUri();
            from("timer:monitor" + uri + "?fixedRate=true&period=" + (heartbeatInterval * 1000))
                    .routeId(endpointInfo.getHeartbeatRouteId())
                    .autoStartup(false)
                    .process(new SetTimeStamp(nullMessageBuilder))
                    .setBody(constant(nullMessageBuilder))
                    .doTry()
                        .process(new EndpointInfoProcessor(endpointInfo))
                        .to(uri)
                        .process(new HealthProcessor(endpointInfo, true))
                    .doCatch(Throwable.class)
                        .process(new HealthProcessor(endpointInfo, false))
                        .end();

            uris[index++] = uri;
            routeIds[index] = endpointInfo.getHeartbeatRouteId();
        }

如何丢弃新的大量 messages/stop 计时器,使其不再一次发送所有消息?

设置fixedRate=false。您可以在有关定时器的 JDK 文档中阅读更多关于固定利率的含义:https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#scheduleAtFixedRate(java.util.TimerTask,%20java.util.Date,%20long)