@@ -25,35 +25,33 @@ public RabbitMQStatus(string connectionString)
2525 }
2626
2727 /// <inheritdoc/>
28- public Task < Status > IsReadyAsync ( CancellationToken cancellationToken )
28+ public async Task < Status > IsReadyAsync ( CancellationToken cancellationToken )
2929 {
3030 var factory = new ConnectionFactory ( )
3131 {
3232 Uri = new Uri ( _connectionString )
3333 } ;
34- using ( IConnection connection = CreateConnection ( factory ) )
35- using ( IModel channel = connection . CreateModel ( ) )
36- {
37- return Task . FromResult ( new Status
38- {
39- IsReady = channel . IsOpen ,
40- Message = connection . ToString ( )
41- } ) ;
42- }
34+ await using IConnection connection = await CreateConnectionAsync ( factory , cancellationToken ) ;
35+ await using IChannel channel = await connection . CreateChannelAsync ( cancellationToken : cancellationToken ) ;
36+
37+ return new Status { IsReady = channel . IsOpen , Message = connection . ToString ( ) ! } ;
4338 }
4439
45- private static IConnection CreateConnection (
46- IConnectionFactory connectionFactory )
40+ private static async Task < IConnection > CreateConnectionAsync (
41+ IConnectionFactory connectionFactory ,
42+ CancellationToken cancellationToken )
4743 {
48- string hostname = ( ( ConnectionFactory ) connectionFactory ) . HostName ;
49- return connectionFactory
50- . CreateConnection ( new List < AmqpTcpEndpoint >
44+ var hostname = ( ( ConnectionFactory ) connectionFactory ) . HostName ;
45+
46+ return await connectionFactory . CreateConnectionAsync (
47+ new List < AmqpTcpEndpoint >
5148 {
5249 new AmqpTcpEndpoint (
5350 connectionFactory . Uri ,
5451 new SslOption (
55- serverName : hostname ,
52+ serverName : hostname ,
5653 enabled : false ) )
57- } ) ;
54+ } ,
55+ cancellationToken ) ;
5856 }
5957}
0 commit comments