diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/BarrierMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/BarrierMessageHandler.java index fd0ed2475e..deb126142f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/BarrierMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/BarrierMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand import org.springframework.integration.handler.DiscardingMessageHandler; import org.springframework.integration.handler.MessageTriggerAction; import org.springframework.integration.store.SimpleMessageGroup; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandlingException; @@ -170,7 +171,8 @@ public class BarrierMessageHandler extends AbstractReplyProducingMessageHandler } /** - * Set the name of the channel to which late arriving trigger messages are sent. + * Set the name of the channel to which late arriving trigger messages are sent, + * or request message does not arrive in time. * @param discardChannelName the discard channel. * @since 5.0 */ @@ -179,7 +181,8 @@ public class BarrierMessageHandler extends AbstractReplyProducingMessageHandler } /** - * Set the channel to which late arriving trigger messages are sent. + * Set the channel to which late arriving trigger messages are sent, + * or request message does not arrive in time. * @param discardChannel the discard channel. * @since 5.0 */ @@ -188,8 +191,11 @@ public class BarrierMessageHandler extends AbstractReplyProducingMessageHandler } /** + * Return the discard message channel for trigger action message. + * @return a discard message channel. * @since 5.0 */ + @Nullable @Override public MessageChannel getDiscardChannel() { String channelName = this.discardChannelName; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java index 3003841eae..39be5b0a58 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ import org.springframework.integration.aggregator.DefaultAggregatingMessageGroup import org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy; import org.springframework.integration.aggregator.MessageGroupProcessor; import org.springframework.integration.config.ConsumerEndpointFactoryBean; +import org.springframework.lang.Nullable; +import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; /** @@ -43,6 +45,15 @@ public class BarrierSpec extends ConsumerEndpointSpec doGet() { - this.handler = new BarrierMessageHandler(this.timeout, this.outputProcessor, this.correlationStrategy); + if (this.triggerTimeout == null) { + this.handler = new BarrierMessageHandler(this.timeout, this.outputProcessor, this.correlationStrategy); + } + else { + this.handler = + new BarrierMessageHandler(this.timeout, this.triggerTimeout, this.outputProcessor, + this.correlationStrategy); + } + if (this.discardChannel != null) { + this.handler.setDiscardChannel(this.discardChannel); + } + else if (this.discardChannelName != null) { + this.handler.setDiscardChannelName(this.discardChannelName); + } return super.doGet(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java index 8b63145d1b..67ef2aab9d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java @@ -300,6 +300,7 @@ public class CorrelationHandlerTests { return f -> f .barrier(10000, b -> b .correlationStrategy(new HeaderAttributeCorrelationStrategy(BARRIER)) + .discardChannel("nullChannel") .outputProcessor(g -> g.getMessages() .stream() diff --git a/src/reference/antora/modules/ROOT/pages/barrier.adoc b/src/reference/antora/modules/ROOT/pages/barrier.adoc index 95ce680881..f0fb5e1731 100644 --- a/src/reference/antora/modules/ROOT/pages/barrier.adoc +++ b/src/reference/antora/modules/ROOT/pages/barrier.adoc @@ -75,5 +75,6 @@ XML:: Depending on which one has a message arrive first, either the thread sending a message to `in` or the thread sending a message to `release` waits for up to ten seconds until the other message arrives. When the message is released, the `out` channel is sent a message that combines the result of invoking the custom `MessageGroupProcessor` bean, named `myOutputProcessor`. If the main thread times out and a trigger arrives later, you can configure a discard channel to which the late trigger is sent. +The trigger message is also discarded if request message does not arrive in time. For an example of this component, see the https://github.com/spring-projects/spring-integration-samples/tree/main/basic/barrier[barrier sample application].