Skip to content

Commit bb6aeec

Browse files
author
Stefán J. Sigurðarson
committed
Merge branch 'master' into crossPlatformSerialization
2 parents d72f5f1 + 5e1f745 commit bb6aeec

File tree

103 files changed

+758
-1184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+758
-1184
lines changed

projects/client/RabbitMQ.Client/src/client/api/AsyncDefaultBasicConsumer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
56
using RabbitMQ.Client.Events;
7+
68
using TaskExtensions = RabbitMQ.Client.Impl.TaskExtensions;
79

810
namespace RabbitMQ.Client
@@ -138,13 +140,9 @@ public virtual Task HandleModelShutdown(object model, ShutdownEventArgs reason)
138140
public virtual async Task OnCancel(params string[] consumerTags)
139141
{
140142
IsRunning = false;
141-
AsyncEventHandler<ConsumerEventArgs> handler = ConsumerCancelled;
142-
if (handler != null)
143+
foreach (AsyncEventHandler<ConsumerEventArgs> h in ConsumerCancelled?.GetInvocationList() ?? Array.Empty<Delegate>())
143144
{
144-
foreach (AsyncEventHandler<ConsumerEventArgs> h in handler.GetInvocationList())
145-
{
146-
await h(this, new ConsumerEventArgs(consumerTags)).ConfigureAwait(false);
147-
}
145+
await h(this, new ConsumerEventArgs(consumerTags)).ConfigureAwait(false);
148146
}
149147

150148
foreach (string consumerTag in consumerTags)

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -505,25 +505,13 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
505505
return conn;
506506
}
507507

508-
private IFrameHandler CreateFrameHandler()
509-
{
510-
IFrameHandler fh = Protocols.DefaultProtocol.CreateFrameHandler(Endpoint, SocketFactory,
511-
RequestedConnectionTimeout, SocketReadTimeout, SocketWriteTimeout);
512-
return ConfigureFrameHandler(fh);
513-
}
514-
515508
internal IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint)
516509
{
517510
IFrameHandler fh = Protocols.DefaultProtocol.CreateFrameHandler(endpoint, SocketFactory,
518511
RequestedConnectionTimeout, SocketReadTimeout, SocketWriteTimeout);
519512
return ConfigureFrameHandler(fh);
520513
}
521514

522-
private IFrameHandler CreateFrameHandlerForHostname(string hostname)
523-
{
524-
return CreateFrameHandler(Endpoint.CloneWithHostname(hostname));
525-
}
526-
527515
private IFrameHandler ConfigureFrameHandler(IFrameHandler fh)
528516
{
529517
// TODO: add user-provided configurator, like in the Java client

projects/client/RabbitMQ.Client/src/client/api/DefaultBasicConsumer.cs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
using System;
4242
using System.Collections.Generic;
4343
using System.Linq;
44+
4445
using RabbitMQ.Client.Events;
4546

4647
namespace RabbitMQ.Client
@@ -58,7 +59,6 @@ public class DefaultBasicConsumer : IBasicConsumer
5859
{
5960
private readonly object _eventLock = new object();
6061
private readonly HashSet<string> _consumerTags = new HashSet<string>();
61-
public EventHandler<ConsumerEventArgs> m_consumerCancelled;
6262

6363
/// <summary>
6464
/// Creates a new instance of an <see cref="DefaultBasicConsumer"/>.
@@ -87,7 +87,8 @@ public DefaultBasicConsumer(IModel model)
8787
/// This value is an array because a single consumer instance can be reused to consume on
8888
/// multiple channels.
8989
/// </summary>
90-
public string[] ConsumerTags {
90+
public string[] ConsumerTags
91+
{
9192
get
9293
{
9394
return _consumerTags.ToArray();
@@ -108,23 +109,7 @@ public string[] ConsumerTags {
108109
/// <summary>
109110
/// Signalled when the consumer gets cancelled.
110111
/// </summary>
111-
public event EventHandler<ConsumerEventArgs> ConsumerCancelled
112-
{
113-
add
114-
{
115-
lock (_eventLock)
116-
{
117-
m_consumerCancelled += value;
118-
}
119-
}
120-
remove
121-
{
122-
lock (_eventLock)
123-
{
124-
m_consumerCancelled -= value;
125-
}
126-
}
127-
}
112+
public event EventHandler<ConsumerEventArgs> ConsumerCancelled;
128113

129114
/// <summary>
130115
/// Retrieve the <see cref="IModel"/> this consumer is associated with,
@@ -202,17 +187,9 @@ public virtual void HandleModelShutdown(object model, ShutdownEventArgs reason)
202187
public virtual void OnCancel(params string[] consumerTags)
203188
{
204189
IsRunning = false;
205-
EventHandler<ConsumerEventArgs> handler;
206-
lock (_eventLock)
207-
{
208-
handler = m_consumerCancelled;
209-
}
210-
if (handler != null)
190+
foreach (EventHandler<ConsumerEventArgs> h in ConsumerCancelled?.GetInvocationList() ?? Array.Empty<Delegate>())
211191
{
212-
foreach (EventHandler<ConsumerEventArgs> h in handler.GetInvocationList())
213-
{
214-
h(this, new ConsumerEventArgs(consumerTags));
215-
}
192+
h(this, new ConsumerEventArgs(consumerTags));
216193
}
217194

218195
foreach (string consumerTag in consumerTags)

projects/client/RabbitMQ.Client/src/client/api/DefaultEndpointResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Linq;
4342
using System.Collections.Generic;
43+
using System.Linq;
4444

4545
namespace RabbitMQ.Client
4646
{

projects/client/RabbitMQ.Client/src/client/api/IAsyncBasicConsumer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Threading.Tasks;
2+
23
using RabbitMQ.Client.Events;
34

45
namespace RabbitMQ.Client

projects/client/RabbitMQ.Client/src/client/api/IBasicConsumer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42+
4243
using RabbitMQ.Client.Events;
4344

4445
namespace RabbitMQ.Client

projects/client/RabbitMQ.Client/src/client/api/IConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
using System.Collections.Generic;
4343
using System.IO;
4444
using System.Threading;
45+
4546
using RabbitMQ.Client.Events;
4647
using RabbitMQ.Client.Exceptions;
4748

projects/client/RabbitMQ.Client/src/client/api/IConnectionFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
using System;
4242
using System.Collections.Generic;
43+
4344
using RabbitMQ.Client.Exceptions;
4445

4546
namespace RabbitMQ.Client

projects/client/RabbitMQ.Client/src/client/api/IModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41-
using RabbitMQ.Client.Apigen.Attributes;
42-
using RabbitMQ.Client.Events;
4341
using System;
4442
using System.Collections.Generic;
4543

44+
using RabbitMQ.Client.Apigen.Attributes;
45+
using RabbitMQ.Client.Events;
46+
4647
namespace RabbitMQ.Client
4748
{
4849
/// <summary>

projects/client/RabbitMQ.Client/src/client/api/ITcpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Threading.Tasks;
32
using System.Net.Sockets;
3+
using System.Threading.Tasks;
44

55
namespace RabbitMQ.Client
66
{

projects/client/RabbitMQ.Client/src/client/api/TopologyRecoveryException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42+
4243
using RabbitMQ.Client.Exceptions;
4344

4445
namespace RabbitMQ.Client

projects/client/RabbitMQ.Client/src/client/content/BasicMessageBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
using System.Collections.Generic;
4242
using System.IO;
43+
4344
using RabbitMQ.Util;
4445

4546
namespace RabbitMQ.Client.Content

projects/client/RabbitMQ.Client/src/client/content/BasicMessageReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
using System.Collections.Generic;
4242
using System.IO;
43+
4344
using RabbitMQ.Util;
4445

4546
namespace RabbitMQ.Client.Content

projects/client/RabbitMQ.Client/src/client/content/MapWireFormatting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System.Collections.Generic;
42+
4243
using RabbitMQ.Util;
4344

4445
namespace RabbitMQ.Client.Content
Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
21
using System.Threading.Tasks;
3-
using TaskExtensions = RabbitMQ.Client.Impl.TaskExtensions;
42

53
namespace RabbitMQ.Client.Events
64
{
@@ -28,57 +26,30 @@ public AsyncEventingBasicConsumer(IModel model) : base(model)
2826
public override async Task HandleBasicCancelOk(string consumerTag)
2927
{
3028
await base.HandleBasicCancelOk(consumerTag).ConfigureAwait(false);
31-
await Raise(Unregistered, new ConsumerEventArgs(new []{consumerTag})).ConfigureAwait(false);
29+
await (Unregistered?.Invoke(this, new ConsumerEventArgs(new[] { consumerTag })) ?? Task.CompletedTask).ConfigureAwait(false);
3230
}
3331

3432
///<summary>Fires the Registered event.</summary>
3533
public override async Task HandleBasicConsumeOk(string consumerTag)
3634
{
3735
await base.HandleBasicConsumeOk(consumerTag).ConfigureAwait(false);
38-
await Raise(Registered, new ConsumerEventArgs(new[] { consumerTag })).ConfigureAwait(false);
36+
await (Registered?.Invoke(this, new ConsumerEventArgs(new[] { consumerTag })) ?? Task.CompletedTask).ConfigureAwait(false);
3937
}
4038

4139
///<summary>Fires the Received event.</summary>
42-
public override async Task HandleBasicDeliver(string consumerTag,
43-
ulong deliveryTag,
44-
bool redelivered,
45-
string exchange,
46-
string routingKey,
47-
IBasicProperties properties,
48-
byte[] body)
40+
public override async Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
4941
{
50-
await base.HandleBasicDeliver(consumerTag,
51-
deliveryTag,
52-
redelivered,
53-
exchange,
54-
routingKey,
55-
properties,
56-
body).ConfigureAwait(false);
57-
await Raise(Received, new BasicDeliverEventArgs(consumerTag,
58-
deliveryTag,
59-
redelivered,
60-
exchange,
61-
routingKey,
62-
properties,
63-
body)).ConfigureAwait(false);
42+
await base.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body).ConfigureAwait(false);
43+
await (Received?.Invoke(
44+
this,
45+
new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body)) ?? Task.CompletedTask).ConfigureAwait(false);
6446
}
6547

6648
///<summary>Fires the Shutdown event.</summary>
6749
public override async Task HandleModelShutdown(object model, ShutdownEventArgs reason)
6850
{
6951
await base.HandleModelShutdown(model, reason).ConfigureAwait(false);
70-
await Raise(Shutdown, reason).ConfigureAwait(false);
71-
}
72-
73-
private Task Raise<TEvent>(AsyncEventHandler<TEvent> eventHandler, TEvent evt)
74-
where TEvent : EventArgs
75-
{
76-
AsyncEventHandler<TEvent> handler = eventHandler;
77-
if (handler != null)
78-
{
79-
return handler(this, evt);
80-
}
81-
return TaskExtensions.CompletedTask;
52+
await (Shutdown?.Invoke(this, reason) ?? Task.CompletedTask).ConfigureAwait(false);
8253
}
8354
}
84-
}
55+
}

projects/client/RabbitMQ.Client/src/client/events/EventingBasicConsumer.cs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,55 +68,30 @@ public EventingBasicConsumer(IModel model) : base(model)
6868
public override void HandleBasicCancelOk(string consumerTag)
6969
{
7070
base.HandleBasicCancelOk(consumerTag);
71-
Raise(Unregistered, new ConsumerEventArgs(new[] { consumerTag }));
71+
Unregistered?.Invoke(this, new ConsumerEventArgs(new[] { consumerTag }));
7272
}
7373

7474
///<summary>Fires the Registered event.</summary>
7575
public override void HandleBasicConsumeOk(string consumerTag)
7676
{
7777
base.HandleBasicConsumeOk(consumerTag);
78-
Raise(Registered, new ConsumerEventArgs(new[] { consumerTag }));
78+
Registered?.Invoke(this, new ConsumerEventArgs(new[] { consumerTag }));
7979
}
8080

8181
///<summary>Fires the Received event.</summary>
82-
public override void HandleBasicDeliver(string consumerTag,
83-
ulong deliveryTag,
84-
bool redelivered,
85-
string exchange,
86-
string routingKey,
87-
IBasicProperties properties,
88-
byte[] body)
82+
public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
8983
{
90-
base.HandleBasicDeliver(consumerTag,
91-
deliveryTag,
92-
redelivered,
93-
exchange,
94-
routingKey,
95-
properties,
96-
body);
97-
Raise(Received, new BasicDeliverEventArgs(consumerTag,
98-
deliveryTag,
99-
redelivered,
100-
exchange,
101-
routingKey,
102-
properties,
103-
body));
84+
base.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
85+
Received?.Invoke(
86+
this,
87+
new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body));
10488
}
10589

10690
///<summary>Fires the Shutdown event.</summary>
10791
public override void HandleModelShutdown(object model, ShutdownEventArgs reason)
10892
{
10993
base.HandleModelShutdown(model, reason);
110-
Raise(Shutdown, reason);
111-
}
112-
113-
private void Raise<TEvent>(EventHandler<TEvent> eventHandler, TEvent evt)
114-
{
115-
EventHandler<TEvent> handler = eventHandler;
116-
if(handler != null)
117-
{
118-
handler(this, evt);
119-
}
94+
Shutdown?.Invoke(this, reason);
12095
}
12196
}
12297
}

projects/client/RabbitMQ.Client/src/client/exceptions/ProtocolViolationException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42+
4243
using RabbitMQ.Client.Exceptions;
4344

4445
namespace RabbitMQ.Client

0 commit comments

Comments
 (0)