@@ -1942,28 +1942,7 @@ private Message doSendAndReceiveWithDirect(String exchange, String routingKey, M
19421942 }
19431943 DirectReplyToMessageListenerContainer container = this .directReplyToContainers .get (connectionFactory );
19441944 if (container == null ) {
1945- synchronized (this .directReplyToContainers ) {
1946- container = this .directReplyToContainers .get (connectionFactory );
1947- if (container == null ) {
1948- container = new DirectReplyToMessageListenerContainer (connectionFactory );
1949- container .setMessageListener (this );
1950- container .setBeanName (this .beanName + "#" + this .containerInstance .getAndIncrement ());
1951- if (this .taskExecutor != null ) {
1952- container .setTaskExecutor (this .taskExecutor );
1953- }
1954- if (this .afterReceivePostProcessors != null ) {
1955- container .setAfterReceivePostProcessors (this .afterReceivePostProcessors
1956- .toArray (new MessagePostProcessor [this .afterReceivePostProcessors .size ()]));
1957- }
1958- container .setNoLocal (this .noLocalReplyConsumer );
1959- if (this .replyErrorHandler != null ) {
1960- container .setErrorHandler (this .replyErrorHandler );
1961- }
1962- container .start ();
1963- this .directReplyToContainers .put (connectionFactory , container );
1964- this .replyAddress = Address .AMQ_RABBITMQ_REPLY_TO ;
1965- }
1966- }
1945+ container = createReplyToContainer (connectionFactory );
19671946 }
19681947 ChannelHolder channelHolder = container .getChannelHolder ();
19691948 boolean cancelConsumer = false ;
@@ -1990,6 +1969,33 @@ private Message doSendAndReceiveWithDirect(String exchange, String routingKey, M
19901969 }
19911970 }
19921971
1972+ private DirectReplyToMessageListenerContainer createReplyToContainer (ConnectionFactory connectionFactory ) {
1973+ DirectReplyToMessageListenerContainer container ;
1974+ synchronized (this .directReplyToContainers ) {
1975+ container = this .directReplyToContainers .get (connectionFactory );
1976+ if (container == null ) {
1977+ container = new DirectReplyToMessageListenerContainer (connectionFactory );
1978+ container .setMessageListener (this );
1979+ container .setBeanName (this .beanName + "#" + this .containerInstance .getAndIncrement ());
1980+ if (this .taskExecutor != null ) {
1981+ container .setTaskExecutor (this .taskExecutor );
1982+ }
1983+ if (this .afterReceivePostProcessors != null ) {
1984+ container .setAfterReceivePostProcessors (this .afterReceivePostProcessors
1985+ .toArray (new MessagePostProcessor [this .afterReceivePostProcessors .size ()]));
1986+ }
1987+ container .setNoLocal (this .noLocalReplyConsumer );
1988+ if (this .replyErrorHandler != null ) {
1989+ container .setErrorHandler (this .replyErrorHandler );
1990+ }
1991+ container .start ();
1992+ this .directReplyToContainers .put (connectionFactory , container );
1993+ this .replyAddress = Address .AMQ_RABBITMQ_REPLY_TO ;
1994+ }
1995+ }
1996+ return container ;
1997+ }
1998+
19931999 @ Nullable
19942000 private Message doSendAndReceiveAsListener (final String exchange , final String routingKey , final Message message ,
19952001 @ Nullable final CorrelationData correlationData , Channel channel , boolean noCorrelation ) throws Exception { // NOSONAR
0 commit comments