Skip to content

Commit 03a8933

Browse files
artembilangaryrussell
authored andcommitted
INT-4474: ConsumerEndpointFactoryBean: Fix phase
JIRA: https://jira.spring.io/browse/INT-4474 * Populate proper `Integer.MIN_VALUE` phase for non-`PollingConsumer`s in the `ConsumerEndpointFactoryBean` **Cherry-pick to 5.0.x and 4.3.x**
1 parent 17e794d commit 03a8933

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,6 +57,13 @@
5757

5858

5959
/**
60+
* The {@link FactoryBean} implementation for {@link AbstractEndpoint} population.
61+
* Controls all the necessary properties and lifecycle.
62+
* According the provided {@link MessageChannel} implementation populates
63+
* a {@link PollingConsumer} for the {@link PollableChannel},
64+
* an {@link EventDrivenConsumer} for the {@link SubscribableChannel}
65+
* and {@link ReactiveStreamsConsumer} for all other channel implementations.
66+
*
6067
* @author Mark Fisher
6168
* @author Oleg Zhurakousky
6269
* @author Josh Long
@@ -310,9 +317,15 @@ else if (channel instanceof PollableChannel) {
310317
this.endpoint.setAutoStartup(this.autoStartup);
311318
}
312319
int phase = this.phase;
313-
if (!this.isPhaseSet && this.endpoint instanceof PollingConsumer) {
314-
phase = Integer.MAX_VALUE / 2;
320+
if (!this.isPhaseSet) {
321+
if (this.endpoint instanceof PollingConsumer) {
322+
phase = Integer.MAX_VALUE / 2;
323+
}
324+
else {
325+
phase = Integer.MIN_VALUE;
326+
}
315327
}
328+
316329
this.endpoint.setPhase(phase);
317330
this.endpoint.setRole(this.role);
318331
if (this.taskScheduler != null) {

spring-integration-core/src/test/java/org/springframework/integration/config/xml/ServiceActivatorParserTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
2929
import org.springframework.context.support.ClassPathXmlApplicationContext;
3030
import org.springframework.integration.core.MessagingTemplate;
31+
import org.springframework.integration.endpoint.EventDrivenConsumer;
3132
import org.springframework.integration.handler.ServiceActivatingHandler;
3233
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
3334
import org.springframework.messaging.Message;
@@ -38,6 +39,8 @@
3839
/**
3940
* @author Mark Fisher
4041
* @author Gary Russell
42+
* @author Artem Bilan
43+
*
4144
* @since 2.0
4245
*/
4346
@ContextConfiguration
@@ -75,6 +78,10 @@ public class ServiceActivatorParserTests {
7578
@Qualifier("testAlias.handler")
7679
private ServiceActivatingHandler testAlias;
7780

81+
@Autowired
82+
@Qualifier("testAlias")
83+
private EventDrivenConsumer testAliasEndpoint;
84+
7885
@Test
7986
public void literalExpression() {
8087
Object result = this.sendAndReceive(literalExpressionInput, "hello");
@@ -200,6 +207,11 @@ public void failMethodAndExpressionElement() {
200207
}
201208
}
202209

210+
@Test
211+
public void testConsumerEndpointFactoryBeanDefaultPhase() {
212+
assertEquals(Integer.MIN_VALUE, this.testAliasEndpoint.getPhase());
213+
}
214+
203215
private Object sendAndReceive(MessageChannel channel, Object payload) {
204216
MessagingTemplate template = new MessagingTemplate();
205217
template.setDefaultDestination(channel);
@@ -222,6 +234,7 @@ public String caps(String s) {
222234
public String concat(String s1, String s2) {
223235
return s1 + s2;
224236
}
237+
225238
}
226239

227240

@@ -235,6 +248,7 @@ private static class TestPayload {
235248
public String getSimpleClassName(Object o) {
236249
return o.getClass().getSimpleName();
237250
}
251+
238252
}
239253

240254

@@ -257,6 +271,7 @@ public String getFirstName() {
257271
public String getLastName() {
258272
return lastName;
259273
}
274+
260275
}
261276

262277
public static class BarAdvice extends AbstractRequestHandlerAdvice {
@@ -268,4 +283,5 @@ protected Object doInvoke(ExecutionCallback callback, Object target, Message<?>
268283
}
269284

270285
}
286+
271287
}

0 commit comments

Comments
 (0)