4242import org .springframework .integration .support .ErrorMessageStrategy ;
4343import org .springframework .integration .support .ErrorMessageUtils ;
4444import org .springframework .retry .RecoveryCallback ;
45- import org .springframework .retry .RetryCallback ;
46- import org .springframework .retry .RetryContext ;
47- import org .springframework .retry .RetryListener ;
45+ import org .springframework .retry .support .RetrySynchronizationManager ;
4846import org .springframework .retry .support .RetryTemplate ;
4947import org .springframework .util .Assert ;
5048import org .springframework .util .StringUtils ;
@@ -190,9 +188,6 @@ protected void onInit() throws Exception {
190188 + "send an error message when retries are exhausted" );
191189 }
192190 Listener messageListener = new Listener ();
193- if (this .retryTemplate != null ) {
194- this .retryTemplate .registerListener (messageListener );
195- }
196191 this .messageListenerContainer .setMessageListener (messageListener );
197192 this .messageListenerContainer .afterPropertiesSet ();
198193 if (!this .amqpTemplateExplicitlySet ) {
@@ -232,7 +227,9 @@ private void setAttributesIfNecessary(Message amqpMessage, org.springframework.m
232227 attributesHolder .set (ErrorMessageUtils .getAttributeAccessor (null , null ));
233228 }
234229 if (needAttributes ) {
235- AttributeAccessor attributes = attributesHolder .get ();
230+ AttributeAccessor attributes = this .retryTemplate != null
231+ ? RetrySynchronizationManager .getContext ()
232+ : attributesHolder .get ();
236233 if (attributes != null ) {
237234 attributes .setAttribute (ErrorMessageUtils .INPUT_MESSAGE_CONTEXT_KEY , message );
238235 attributes .setAttribute (AmqpMessageHeaderErrorMessageStrategy .AMQP_RAW_MESSAGE , amqpMessage );
@@ -251,7 +248,7 @@ protected AttributeAccessor getErrorMessageAttributes(org.springframework.messag
251248 }
252249 }
253250
254- protected class Listener implements ChannelAwareMessageListener , RetryListener {
251+ protected class Listener implements ChannelAwareMessageListener {
255252
256253 @ SuppressWarnings ("unchecked" )
257254 @ Override
@@ -362,26 +359,6 @@ private void process(Message message, org.springframework.messaging.Message<Obje
362359 }
363360 }
364361
365- @ Override
366- public <T , E extends Throwable > boolean open (RetryContext context , RetryCallback <T , E > callback ) {
367- if (AmqpInboundGateway .this .recoveryCallback != null ) {
368- attributesHolder .set (context );
369- }
370- return true ;
371- }
372-
373- @ Override
374- public <T , E extends Throwable > void close (RetryContext context , RetryCallback <T , E > callback ,
375- Throwable throwable ) {
376- attributesHolder .remove ();
377- }
378-
379- @ Override
380- public <T , E extends Throwable > void onError (RetryContext context , RetryCallback <T , E > callback ,
381- Throwable throwable ) {
382- // Empty
383- }
384-
385362 }
386363
387364}
0 commit comments