DelayHandler messageGroupId

DelayHandler messageGroupId

从 Spring 集成文档 (https://docs.spring.io/spring-integration/docs/5.1.7.RELEASE/reference/html/#delayer) 我不清楚 DelayHandler 中的 messageGroupId 的确切含义以及我必须在那里准确设置的值(它是任意的吗?) .该值在 xml 配置中不存在,但在 Java 配置中存在。

@ServiceActivator(inputChannel = "input")
@Bean
public DelayHandler delayer() {
   DelayHandler handler = new DelayHandler("delayer.messageGroupId"); // THIS constructor parameter is not clear to me
   handler.setDefaultDelay(3_000L);
   handler.setDelayExpressionString("headers['delay']");
   handler.setOutputChannelName("output");
   return handler;
}

在该构造函数的 JavaDocs 中有解释:

/**
 * Create a DelayHandler with the given 'messageGroupId' that is used as 'key' for
 * {@link MessageGroup} to store delayed Messages in the {@link MessageGroupStore}.
 * The sending of Messages after the delay will be handled by registered in the
 * ApplicationContext default
 * {@link org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler}.
 * @param messageGroupId The message group identifier.
 * @see #getTaskScheduler()
 */
public DelayHandler(String messageGroupId) {

不需要,因为 groupId 基于所需的 id 属性:

    String id = element.getAttribute(ID_ATTRIBUTE);
    if (!StringUtils.hasText(id)) {
        parserContext.getReaderContext().error("The 'id' attribute is required.", element);
    }
    ...
    builder.addConstructorArgValue(id + ".messageGroupId");

确实在文档中提到并解释了一点:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#delayer-namespace

该值确实是任意的,但对于您的应用程序来说它必须是唯一的,因此不同的延迟器不会互相窃取消息。