3131
3232using System ;
3333using System . Collections . Generic ;
34- using System . Diagnostics ;
3534using System . Threading ;
3635using System . Threading . Tasks ;
3736using RabbitMQ . Client . client . impl ;
@@ -42,105 +41,124 @@ public static class IChannelExtensions
4241 {
4342 /// <summary>Asynchronously start a Basic content-class consumer.</summary>
4443 public static Task < string > BasicConsumeAsync ( this IChannel channel ,
45- IAsyncBasicConsumer consumer ,
4644 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 ,
5945 bool autoAck ,
6046 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 ) ;
6551
6652 /// <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 ,
6855 bool autoAck ,
6956 string consumerTag ,
7057 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 ) ;
7562
7663 /// <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 ,
7866 bool autoAck ,
7967 string consumerTag ,
8068 IDictionary < string , object ? > ? arguments ,
8169 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 ) ;
8674
8775 /// <summary>
8876 /// (Extension method) Convenience overload of BasicPublish.
8977 /// </summary>
9078 /// <remarks>
9179 /// The publication occurs with mandatory=false and immediate=false.
9280 /// </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 ) ;
9990
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 ) ;
103100
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 ) ;
107110
108111 /// <summary>
109112 /// Asynchronously declare a queue.
110113 /// </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 ,
115123 durable : durable , exclusive : exclusive , autoDelete : autoDelete ,
116- arguments : arguments , noWait : noWait , cancellationToken : cancellationToken ) ;
117- }
124+ arguments : arguments , noWait : noWait ,
125+ cancellationToken : cancellationToken ) ;
118126
119127 /// <summary>
120128 /// Asynchronously declare an exchange.
121129 /// </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 ) ;
128141
129142 /// <summary>
130143 /// Asynchronously deletes a queue.
131144 /// </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 ) ;
136151
137152 /// <summary>
138153 /// Asynchronously unbinds a queue.
139154 /// </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 ) ;
144162
145163 /// <summary>
146164 /// Asynchronously abort this session.
@@ -153,11 +171,10 @@ public static Task QueueUnbindAsync(this IChannel channel, string queue, string
153171 /// In comparison to normal <see cref="CloseAsync(IChannel, CancellationToken)"/> method, <see cref="AbortAsync(IChannel, CancellationToken)"/> will not throw
154172 /// <see cref="Exceptions.AlreadyClosedException"/> or <see cref="System.IO.IOException"/> or any other <see cref="Exception"/> during closing channel.
155173 /// </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 ,
159177 cancellationToken ) ;
160- }
161178
162179 /// <summary>Asynchronously close this session.</summary>
163180 /// <remarks>
@@ -166,11 +183,10 @@ public static Task AbortAsync(this IChannel channel, CancellationToken cancellat
166183 /// operation to complete. This method will not return to the
167184 /// caller until the shutdown is complete.
168185 /// </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 ,
172189 cancellationToken ) ;
173- }
174190
175191 /// <summary>
176192 /// Asynchronously close this channel.
@@ -189,10 +205,10 @@ public static Task CloseAsync(this IChannel channel, CancellationToken cancellat
189205 /// A message indicating the reason for closing the channel
190206 /// </para>
191207 /// </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 ) ;
197213 }
198214}
0 commit comments