Fix MessagingGatewaySupport implementors

The `AmqpInboundGateway` and `JmsInboundGateway` don't delegate to `super`
in their `doStart()/doStop()` implementations causing the problem with
an internal `replyMessageCorrelator` missed the proper lifecycle
management

**Cherry-pick to 5.1.x & 5.0.x**
This commit is contained in:
Artem Bilan
2019-05-08 13:35:11 -04:00
committed by Gary Russell
parent 34bcd7d60c
commit 756cd41085
2 changed files with 14 additions and 9 deletions

View File

@@ -65,7 +65,7 @@ import com.rabbitmq.client.Channel;
*/
public class AmqpInboundGateway extends MessagingGatewaySupport {
private static final ThreadLocal<AttributeAccessor> attributesHolder = new ThreadLocal<AttributeAccessor>();
private static final ThreadLocal<AttributeAccessor> attributesHolder = new ThreadLocal<>();
private final AbstractMessageListenerContainer messageListenerContainer;
@@ -208,11 +208,13 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
@Override
protected void doStart() {
super.doStart();
this.messageListenerContainer.start();
}
@Override
protected void doStop() {
super.doStop();
this.messageListenerContainer.stop();
}
@@ -271,11 +273,11 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
org.springframework.messaging.Message<Object> converted = convert(message, channel);
if (converted != null) {
AmqpInboundGateway.this.retryTemplate.execute(context -> {
StaticMessageHeaderAccessor.getDeliveryAttempt(converted).incrementAndGet();
process(message, converted);
return null;
},
(RecoveryCallback<Object>) AmqpInboundGateway.this.recoveryCallback);
StaticMessageHeaderAccessor.getDeliveryAttempt(converted).incrementAndGet();
process(message, converted);
return null;
},
(RecoveryCallback<Object>) AmqpInboundGateway.this.recoveryCallback);
}
}
}
@@ -305,9 +307,9 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
return null;
}
return getMessageBuilderFactory()
.withPayload(payload)
.copyHeaders(headers)
.build();
.withPayload(payload)
.copyHeaders(headers)
.build();
}
private void process(Message message, org.springframework.messaging.Message<Object> messagingMessage) {

View File

@@ -39,6 +39,7 @@ public class JmsInboundGateway extends MessagingGatewaySupport implements Dispos
public JmsInboundGateway(AbstractMessageListenerContainer listenerContainer,
ChannelPublishingJmsMessageListener listener) {
this.endpoint = new JmsMessageDrivenEndpoint(listenerContainer, listener);
}
@@ -78,11 +79,13 @@ public class JmsInboundGateway extends MessagingGatewaySupport implements Dispos
@Override
protected void doStart() {
super.doStart();
this.endpoint.start();
}
@Override
protected void doStop() {
super.doStop();
this.endpoint.stop();
}