31
31
32
32
using System ;
33
33
using System . Collections . Generic ;
34
- using System . Diagnostics ;
35
34
using System . Threading ;
36
35
using System . Threading . Tasks ;
37
36
using RabbitMQ . Client . client . impl ;
@@ -42,105 +41,124 @@ public static class IChannelExtensions
42
41
{
43
42
/// <summary>Asynchronously start a Basic content-class consumer.</summary>
44
43
public static Task < string > BasicConsumeAsync ( this IChannel channel ,
45
- IAsyncBasicConsumer consumer ,
46
44
string queue ,
47
- bool autoAck = false ,
48
- string consumerTag = "" ,
49
- bool noLocal = false ,
50
- bool exclusive = false ,
51
- IDictionary < string , object ? > ? arguments = null ,
52
- CancellationToken cancellationToken = default )
53
- {
54
- return channel . BasicConsumeAsync ( queue , autoAck , consumerTag , noLocal , exclusive , arguments , consumer , cancellationToken ) ;
55
- }
56
-
57
- /// <summary>Asynchronously start a Basic content-class consumer.</summary>
58
- public static Task < string > BasicConsumeAsync ( this IChannel channel , string queue ,
59
45
bool autoAck ,
60
46
IAsyncBasicConsumer consumer ,
61
- CancellationToken cancellationToken = default )
62
- {
63
- return channel . BasicConsumeAsync ( queue , autoAck , string . Empty , false , false , null , consumer , cancellationToken ) ;
64
- }
47
+ CancellationToken cancellationToken = default ) =>
48
+ channel . BasicConsumeAsync ( queue : queue , autoAck : autoAck , consumerTag : string . Empty ,
49
+ noLocal : false , exclusive : false , arguments : null , consumer : consumer ,
50
+ cancellationToken ) ;
65
51
66
52
/// <summary>Asynchronously start a Basic content-class consumer.</summary>
67
- public static Task < string > BasicConsumeAsync ( this IChannel channel , string queue ,
53
+ public static Task < string > BasicConsumeAsync ( this IChannel channel ,
54
+ string queue ,
68
55
bool autoAck ,
69
56
string consumerTag ,
70
57
IAsyncBasicConsumer consumer ,
71
- CancellationToken cancellationToken = default )
72
- {
73
- return channel . BasicConsumeAsync ( queue , autoAck , consumerTag , false , false , null , consumer , cancellationToken ) ;
74
- }
58
+ CancellationToken cancellationToken = default ) =>
59
+ channel . BasicConsumeAsync ( queue : queue , autoAck : autoAck , consumerTag : consumerTag ,
60
+ noLocal : false , exclusive : false , arguments : null , consumer : consumer ,
61
+ cancellationToken ) ;
75
62
76
63
/// <summary>Asynchronously start a Basic content-class consumer.</summary>
77
- public static Task < string > BasicConsumeAsync ( this IChannel channel , string queue ,
64
+ public static Task < string > BasicConsumeAsync ( this IChannel channel ,
65
+ string queue ,
78
66
bool autoAck ,
79
67
string consumerTag ,
80
68
IDictionary < string , object ? > ? arguments ,
81
69
IAsyncBasicConsumer consumer ,
82
- CancellationToken cancellationToken = default )
83
- {
84
- return channel . BasicConsumeAsync ( queue , autoAck , consumerTag , false , false , arguments , consumer , cancellationToken ) ;
85
- }
70
+ CancellationToken cancellationToken = default ) =>
71
+ channel . BasicConsumeAsync ( queue : queue , autoAck : autoAck , consumerTag : consumerTag ,
72
+ noLocal : false , exclusive : false , arguments : arguments , consumer : consumer ,
73
+ cancellationToken ) ;
86
74
87
75
/// <summary>
88
76
/// (Extension method) Convenience overload of BasicPublish.
89
77
/// </summary>
90
78
/// <remarks>
91
79
/// The publication occurs with mandatory=false and immediate=false.
92
80
/// </remarks>
93
- public static ValueTask BasicPublishAsync < T > ( this IChannel channel , PublicationAddress addr , T basicProperties ,
94
- ReadOnlyMemory < byte > body , CancellationToken cancellationToken = default )
95
- where T : IReadOnlyBasicProperties , IAmqpHeader
96
- {
97
- return channel . BasicPublishAsync ( addr . ExchangeName , addr . RoutingKey , basicProperties , body , false , cancellationToken ) ;
98
- }
81
+ public static ValueTask BasicPublishAsync < T > ( this IChannel channel ,
82
+ PublicationAddress addr ,
83
+ T basicProperties ,
84
+ ReadOnlyMemory < byte > body ,
85
+ CancellationToken cancellationToken = default )
86
+ where T : IReadOnlyBasicProperties , IAmqpHeader =>
87
+ channel . BasicPublishAsync ( exchange : addr . ExchangeName , routingKey : addr . RoutingKey ,
88
+ basicProperties : basicProperties , body : body , mandatory : false ,
89
+ cancellationToken ) ;
99
90
100
- public static ValueTask BasicPublishAsync ( this IChannel channel , string exchange , string routingKey ,
101
- ReadOnlyMemory < byte > body = default , bool mandatory = false , CancellationToken cancellationToken = default ) =>
102
- channel . BasicPublishAsync ( exchange , routingKey , EmptyBasicProperty . Empty , body , mandatory , cancellationToken ) ;
91
+ public static ValueTask BasicPublishAsync ( this IChannel channel ,
92
+ string exchange ,
93
+ string routingKey ,
94
+ ReadOnlyMemory < byte > body = default ,
95
+ bool mandatory = false ,
96
+ CancellationToken cancellationToken = default ) =>
97
+ channel . BasicPublishAsync ( exchange : exchange , routingKey : routingKey ,
98
+ basicProperties : EmptyBasicProperty . Empty , body : body , mandatory : mandatory ,
99
+ cancellationToken ) ;
103
100
104
- public static ValueTask BasicPublishAsync ( this IChannel channel , CachedString exchange ,
105
- CachedString routingKey , ReadOnlyMemory < byte > body = default , bool mandatory = false , CancellationToken cancellationToken = default ) =>
106
- channel . BasicPublishAsync ( exchange , routingKey , EmptyBasicProperty . Empty , body , mandatory , cancellationToken ) ;
101
+ public static ValueTask BasicPublishAsync ( this IChannel channel ,
102
+ CachedString exchange ,
103
+ CachedString routingKey ,
104
+ ReadOnlyMemory < byte > body = default ,
105
+ bool mandatory = false ,
106
+ CancellationToken cancellationToken = default ) =>
107
+ channel . BasicPublishAsync ( exchange : exchange , routingKey : routingKey ,
108
+ basicProperties : EmptyBasicProperty . Empty , body : body , mandatory : mandatory ,
109
+ cancellationToken ) ;
107
110
108
111
/// <summary>
109
112
/// Asynchronously declare a queue.
110
113
/// </summary>
111
- public static Task < QueueDeclareOk > QueueDeclareAsync ( this IChannel channel , string queue = "" , bool durable = false , bool exclusive = true ,
112
- bool autoDelete = true , IDictionary < string , object ? > ? arguments = null , bool noWait = false , CancellationToken cancellationToken = default )
113
- {
114
- return channel . QueueDeclareAsync ( queue : queue , passive : false ,
114
+ public static Task < QueueDeclareOk > QueueDeclareAsync ( this IChannel channel ,
115
+ string queue = "" ,
116
+ bool durable = false ,
117
+ bool exclusive = true ,
118
+ bool autoDelete = true ,
119
+ IDictionary < string , object ? > ? arguments = null ,
120
+ bool noWait = false ,
121
+ CancellationToken cancellationToken = default ) =>
122
+ channel . QueueDeclareAsync ( queue : queue , passive : false ,
115
123
durable : durable , exclusive : exclusive , autoDelete : autoDelete ,
116
- arguments : arguments , noWait : noWait , cancellationToken : cancellationToken ) ;
117
- }
124
+ arguments : arguments , noWait : noWait ,
125
+ cancellationToken : cancellationToken ) ;
118
126
119
127
/// <summary>
120
128
/// Asynchronously declare an exchange.
121
129
/// </summary>
122
- public static Task ExchangeDeclareAsync ( this IChannel channel , string exchange , string type , bool durable = false , bool autoDelete = false ,
123
- IDictionary < string , object ? > ? arguments = null , bool noWait = false , CancellationToken cancellationToken = default )
124
- {
125
- return channel . ExchangeDeclareAsync ( exchange , type , durable , autoDelete ,
126
- arguments : arguments , passive : false , noWait : noWait , cancellationToken : cancellationToken ) ;
127
- }
130
+ public static Task ExchangeDeclareAsync ( this IChannel channel ,
131
+ string exchange ,
132
+ string type ,
133
+ bool durable = false ,
134
+ bool autoDelete = false ,
135
+ IDictionary < string , object ? > ? arguments = null ,
136
+ bool noWait = false ,
137
+ CancellationToken cancellationToken = default ) =>
138
+ channel . ExchangeDeclareAsync ( exchange : exchange , type : type , durable : durable ,
139
+ autoDelete : autoDelete , arguments : arguments , passive : false , noWait : noWait ,
140
+ cancellationToken : cancellationToken ) ;
128
141
129
142
/// <summary>
130
143
/// Asynchronously deletes a queue.
131
144
/// </summary>
132
- public static Task < uint > QueueDeleteAsync ( this IChannel channel , string queue , bool ifUnused = false , bool ifEmpty = false , CancellationToken cancellationToken = default )
133
- {
134
- return channel . QueueDeleteAsync ( queue , ifUnused , ifEmpty , false , cancellationToken ) ;
135
- }
145
+ public static Task < uint > QueueDeleteAsync ( this IChannel channel ,
146
+ string queue ,
147
+ bool ifUnused = false ,
148
+ bool ifEmpty = false ,
149
+ CancellationToken cancellationToken = default ) =>
150
+ channel . QueueDeleteAsync ( queue , ifUnused , ifEmpty , false , cancellationToken ) ;
136
151
137
152
/// <summary>
138
153
/// Asynchronously unbinds a queue.
139
154
/// </summary>
140
- public static Task QueueUnbindAsync ( this IChannel channel , string queue , string exchange , string routingKey , IDictionary < string , object ? > ? arguments = null , CancellationToken cancellationToken = default )
141
- {
142
- return channel . QueueUnbindAsync ( queue , exchange , routingKey , arguments , cancellationToken ) ;
143
- }
155
+ public static Task QueueUnbindAsync ( this IChannel channel ,
156
+ string queue ,
157
+ string exchange ,
158
+ string routingKey ,
159
+ IDictionary < string , object ? > ? arguments = null ,
160
+ CancellationToken cancellationToken = default ) =>
161
+ channel . QueueUnbindAsync ( queue , exchange , routingKey , arguments , cancellationToken ) ;
144
162
145
163
/// <summary>
146
164
/// Asynchronously abort this session.
@@ -153,11 +171,10 @@ public static Task QueueUnbindAsync(this IChannel channel, string queue, string
153
171
/// In comparison to normal <see cref="CloseAsync(IChannel, CancellationToken)"/> method, <see cref="AbortAsync(IChannel, CancellationToken)"/> will not throw
154
172
/// <see cref="Exceptions.AlreadyClosedException"/> or <see cref="System.IO.IOException"/> or any other <see cref="Exception"/> during closing channel.
155
173
/// </remarks>
156
- public static Task AbortAsync ( this IChannel channel , CancellationToken cancellationToken = default )
157
- {
158
- return channel . CloseAsync ( Constants . ReplySuccess , "Goodbye" , true ,
174
+ public static Task AbortAsync ( this IChannel channel ,
175
+ CancellationToken cancellationToken = default ) =>
176
+ channel . CloseAsync ( Constants . ReplySuccess , "Goodbye" , true ,
159
177
cancellationToken ) ;
160
- }
161
178
162
179
/// <summary>Asynchronously close this session.</summary>
163
180
/// <remarks>
@@ -166,11 +183,10 @@ public static Task AbortAsync(this IChannel channel, CancellationToken cancellat
166
183
/// operation to complete. This method will not return to the
167
184
/// caller until the shutdown is complete.
168
185
/// </remarks>
169
- public static Task CloseAsync ( this IChannel channel , CancellationToken cancellationToken = default )
170
- {
171
- return channel . CloseAsync ( Constants . ReplySuccess , "Goodbye" , false ,
186
+ public static Task CloseAsync ( this IChannel channel ,
187
+ CancellationToken cancellationToken = default ) =>
188
+ channel . CloseAsync ( Constants . ReplySuccess , "Goodbye" , false ,
172
189
cancellationToken ) ;
173
- }
174
190
175
191
/// <summary>
176
192
/// Asynchronously close this channel.
@@ -189,10 +205,10 @@ public static Task CloseAsync(this IChannel channel, CancellationToken cancellat
189
205
/// A message indicating the reason for closing the channel
190
206
/// </para>
191
207
/// </remarks>
192
- public static Task CloseAsync ( this IChannel channel , ushort replyCode , string replyText ,
193
- CancellationToken cancellationToken = default )
194
- {
195
- return channel . CloseAsync ( replyCode , replyText , false , cancellationToken ) ;
196
- }
208
+ public static Task CloseAsync ( this IChannel channel ,
209
+ ushort replyCode ,
210
+ string replyText ,
211
+ CancellationToken cancellationToken = default ) =>
212
+ channel . CloseAsync ( replyCode , replyText , false , cancellationToken ) ;
197
213
}
198
214
}
0 commit comments