@@ -40,11 +40,6 @@ public RabbitMQQuery(ILogger<RabbitMQQuery> logger, TimeProvider timeProvider, I
4040 }
4141 }
4242
43- protected override void InitializeCore ( ReadOnlyDictionary < string , string > settings )
44- {
45- Diagnostics . AppendLine ( "Using settings from connection string" ) ;
46- }
47-
4843 public override async IAsyncEnumerable < QueueThroughput > GetThroughputPerDay ( IBrokerQueue brokerQueue , DateOnly startDate , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
4944 {
5045 var queue = ( RabbitMQBrokerQueueDetails ) brokerQueue ;
@@ -82,34 +77,6 @@ public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBro
8277 }
8378 }
8479
85- async Task GetRabbitDetails ( CancellationToken cancellationToken )
86- {
87- var response = await pipeline . ExecuteAsync ( async async => await managementClient . Value . GetOverview ( cancellationToken ) , cancellationToken ) ;
88-
89- ValidateResponse ( response ) ;
90-
91- if ( response . Value ! . DisableStats )
92- {
93- throw new Exception ( "The RabbitMQ broker is configured with 'management.disable_stats = true' or 'management_agent.disable_metrics_collector = true' " +
94- "and as a result queue statistics cannot be collected using this tool. Consider changing the configuration of the RabbitMQ broker." ) ;
95- }
96-
97- Data [ "RabbitMQVersion" ] = response . Value ? . BrokerVersion ?? "Unknown" ;
98- }
99-
100- void ValidateResponse < T > ( ( HttpStatusCode StatusCode , string Reason , T ? Value ) response )
101- {
102- if ( response . StatusCode != HttpStatusCode . OK )
103- {
104- throw new HttpRequestException ( $ "Request failed with status code { response . StatusCode } : { response . Reason } ") ;
105- }
106-
107- if ( response . Value is null )
108- {
109- throw new InvalidOperationException ( "Request was successful, but the response body was null when a value was expected" ) ;
110- }
111- }
112-
11380 public override async IAsyncEnumerable < IBrokerQueue > GetQueueNames ( [ EnumeratorCancellation ] CancellationToken cancellationToken )
11481 {
11582 var page = 1 ;
@@ -141,6 +108,30 @@ public override async IAsyncEnumerable<IBrokerQueue> GetQueueNames([EnumeratorCa
141108 } while ( morePages ) ;
142109 }
143110
111+ async Task GetRabbitDetails ( CancellationToken cancellationToken )
112+ {
113+ var response = await pipeline . ExecuteAsync ( async async => await managementClient . Value . GetOverview ( cancellationToken ) , cancellationToken ) ;
114+
115+ ValidateResponse ( response ) ;
116+
117+ if ( response . Value ! . DisableStats )
118+ {
119+ throw new Exception ( "The RabbitMQ broker is configured with 'management.disable_stats = true' or 'management_agent.disable_metrics_collector = true' " +
120+ "and as a result queue statistics cannot be collected using this tool. Consider changing the configuration of the RabbitMQ broker." ) ;
121+ }
122+
123+ Data [ "RabbitMQVersion" ] = response . Value ? . BrokerVersion ?? "Unknown" ;
124+ }
125+
126+ internal async Task < ( List < RabbitMQBrokerQueueDetails > ? , bool morePages ) > GetPage ( int page , CancellationToken cancellationToken )
127+ {
128+ var ( StatusCode , Reason , Value , MorePages ) = await pipeline . ExecuteAsync ( async token => await managementClient . Value . GetQueues ( page , 500 , token ) , cancellationToken ) ;
129+
130+ ValidateResponse ( ( StatusCode , Reason , Value ) ) ;
131+
132+ return ( MaterializeQueueDetails ( Value ) , MorePages ) ;
133+ }
134+
144135 async Task AddAdditionalQueueDetails ( RabbitMQBrokerQueueDetails brokerQueue , CancellationToken cancellationToken )
145136 {
146137 try
@@ -181,15 +172,6 @@ async Task AddAdditionalQueueDetails(RabbitMQBrokerQueueDetails brokerQueue, Can
181172 }
182173 }
183174
184- internal async Task < ( List < RabbitMQBrokerQueueDetails > ? , bool morePages ) > GetPage ( int page , CancellationToken cancellationToken )
185- {
186- var ( StatusCode , Reason , Value , MorePages ) = await pipeline . ExecuteAsync ( async token => await managementClient . Value . GetQueues ( page , 500 , token ) , cancellationToken ) ;
187-
188- ValidateResponse ( ( StatusCode , Reason , Value ) ) ;
189-
190- return ( MaterializeQueueDetails ( Value ) , MorePages ) ;
191- }
192-
193175 static List < RabbitMQBrokerQueueDetails > MaterializeQueueDetails ( List < Queue > items )
194176 {
195177 var queues = new List < RabbitMQBrokerQueueDetails > ( ) ;
@@ -201,6 +183,19 @@ static List<RabbitMQBrokerQueueDetails> MaterializeQueueDetails(List<Queue> item
201183 return queues ;
202184 }
203185
186+ void ValidateResponse < T > ( ( HttpStatusCode StatusCode , string Reason , T ? Value ) response )
187+ {
188+ if ( response . StatusCode != HttpStatusCode . OK )
189+ {
190+ throw new HttpRequestException ( $ "Request failed with status code { response . StatusCode } : { response . Reason } ") ;
191+ }
192+
193+ if ( response . Value is null )
194+ {
195+ throw new InvalidOperationException ( "Request was successful, but the response body was null when a value was expected" ) ;
196+ }
197+ }
198+
204199 public override KeyDescriptionPair [ ] Settings => [ ] ;
205200
206201 protected override async Task < ( bool Success , List < string > Errors ) > TestConnectionCore ( CancellationToken cancellationToken )
@@ -223,5 +218,7 @@ static List<RabbitMQBrokerQueueDetails> MaterializeQueueDetails(List<Queue> item
223218 throw new Exception ( $ "Failed to connect to RabbitMQ management API", ex ) ;
224219 }
225220 }
221+
222+ protected override void InitializeCore ( ReadOnlyDictionary < string , string > settings ) => Diagnostics . AppendLine ( "Using settings from connection string" ) ;
226223}
227224
0 commit comments