@@ -354,7 +354,7 @@ public Producer createProducer(Connection connection, Stats stats, MulticastSet.
354354 public Consumer createConsumer (Connection connection , Stats stats , MulticastSet .CompletionHandler completionHandler ) throws IOException {
355355 TopologyHandlerResult topologyHandlerResult = this .topologyHandler .configureQueuesForClient (connection );
356356 connection = topologyHandlerResult .connection ;
357- Channel channel = topologyHandlerResult . channel ;
357+ Channel channel = connection . createChannel () ;
358358 if (consumerTxSize > 0 ) channel .txSelect ();
359359 if (consumerPrefetch > 0 ) channel .basicQos (consumerPrefetch );
360360 if (channelPrefetch > 0 ) channel .basicQos (channelPrefetch , true );
@@ -553,20 +553,13 @@ static class TopologyHandlerResult {
553553 */
554554 final Connection connection ;
555555
556- /**
557- * The channel used to create the configured resources.
558- * Must be used by the agent that asked to declare resources.
559- */
560- final Channel channel ;
561-
562556 /**
563557 * The configured queues.
564558 */
565559 final List <String > configuredQueues ;
566560
567- TopologyHandlerResult (Connection connection , Channel channel , List <String > configuredQueues ) {
561+ TopologyHandlerResult (Connection connection , List <String > configuredQueues ) {
568562 this .connection = connection ;
569- this .channel = channel ;
570563 this .configuredQueues = configuredQueues ;
571564 }
572565 }
@@ -601,7 +594,8 @@ protected Connection maybeUseCachedConnection(List<String> queues, Connection co
601594 return connectionToUse ;
602595 }
603596
604- protected List <String > configureQueues (Connection connection , Channel channel , List <String > queues , Runnable afterQueueConfigurationCallback ) throws IOException {
597+ protected List <String > configureQueues (Connection connection , List <String > queues , Runnable afterQueueConfigurationCallback ) throws IOException {
598+ Channel channel = connection .createChannel ();
605599 if (!params .predeclared || !exchangeExists (connection , params .exchangeName )) {
606600 channel .exchangeDeclare (params .exchangeName , params .exchangeType );
607601 }
@@ -632,6 +626,7 @@ protected List<String> configureQueues(Connection connection, Channel channel, L
632626 }
633627 afterQueueConfigurationCallback .run ();
634628 }
629+ channel .abort ();
635630 return generatedQueueNames ;
636631 }
637632
@@ -665,22 +660,20 @@ public String getRoutingKey() {
665660 public TopologyHandlerResult configureQueuesForClient (Connection connection ) throws IOException {
666661 if (this .params .isExclusive ()) {
667662 Connection connectionToUse = maybeUseCachedConnection (this .queueNames , connection );
668- Channel channel = connectionToUse .createChannel ();
669663 return new TopologyHandlerResult (
670- connectionToUse , channel , configureQueues (connectionToUse , channel , this .queueNames , () -> {})
664+ connectionToUse , configureQueues (connectionToUse , this .queueNames , () -> {})
671665 );
672666 } else {
673- Channel channel = connection .createChannel ();
674667 return new TopologyHandlerResult (
675- connection , channel , configureQueues (connection , channel , this .queueNames , () -> {})
668+ connection , configureQueues (connection , this .queueNames , () -> {})
676669 ) ;
677670 }
678671 }
679672
680673 @ Override
681674 public List <String > configureAllQueues (Connection connection ) throws IOException {
682675 if (shouldConfigureQueues () && !this .params .isExclusive ()) {
683- return configureQueues (connection , connection . createChannel (), this .queueNames , () -> {});
676+ return configureQueues (connection , this .queueNames , () -> {});
684677 }
685678 return null ;
686679 }
@@ -729,17 +722,13 @@ public String getRoutingKey() {
729722 public TopologyHandlerResult configureQueuesForClient (Connection connection ) throws IOException {
730723 if (this .params .isExclusive ()) {
731724 Connection connectionToUse = maybeUseCachedConnection (getQueueNamesForClient (), connection );
732- Channel channel = connectionToUse .createChannel ();
733725 return new TopologyHandlerResult (
734726 connectionToUse ,
735- channel ,
736- configureQueues (connectionToUse , channel , getQueueNamesForClient (), () -> {})
727+ configureQueues (connectionToUse , getQueueNamesForClient (), () -> {})
737728 );
738729 } else {
739- Channel channel = connection .createChannel ();
740730 return new TopologyHandlerResult (
741731 connection ,
742- channel ,
743732 getQueueNamesForClient ()
744733 );
745734 }
@@ -752,8 +741,7 @@ public List<String> configureAllQueues(Connection connection) throws IOException
752741 if (this .params .isExclusive ()) {
753742 return null ;
754743 } else {
755- Channel channel = connection .createChannel ();
756- return configureQueues (connection , channel , getQueueNames (), () -> this .next ());
744+ return configureQueues (connection , getQueueNames (), () -> this .next ());
757745 }
758746 }
759747
0 commit comments