为什么我的timeToLiveFunction从未调用过?

问题描述

我有以下流程:

@Bean
public IntegrationFlow workerInfoJmsOut(ConnectionFactory connectionFactory,WorkerProperties properties) {
  return IntegrationFlows
    .from(ChannelNames.WORKER_INFO)
    .handle(Jms.outboundAdapter(connectionFactory)
      .timetoLiveFunction(message -> properties.getHeartbeatTtl().toMillis())
      .destination(JmsQueueNames.WORKER_INFO))
    .get();
}

以及以下网关:

@MessagingGateway
public interface dispatcherGateway {

  @Gateway(requestChannel = ChannelNames.WORKER_INFO)
  void submit(WorkerMessage message);
}

每1s被叫一次

@Scheduled(fixedDelay = 1000)
public void beat() {
  dispatcherGateway.submit(WorkerInfoNotice.of(...));
}

但是,永远不会命中timetoLiveFunction中的断点:

location of the breakpoint

我是否误解了某件事,或者为什么它从未被击中?

spring-integration-jms:5.3.1.RELEASE

解决方法

我发现我需要启用显式QoS

@Bean
public IntegrationFlow workerInfoJmsOut(ConnectionFactory connectionFactory,WorkerProperties properties) {
  return IntegrationFlows
    .from(ChannelNames.WORKER_INFO)
    .handle(Jms.outboundAdapter(connectionFactory)
      .configureJmsTemplate(spec -> spec.explicitQosEnabled(true))
      .timeToLiveFunction(message -> properties.getHeartbeatTtl().toMillis())
      .destination(JmsQueueNames.WORKER_INFO))
    .get();
}