Skip to content

Commit 486025d

Browse files
committed
Add IConnection XML doc
1 parent 4e9a036 commit 486025d

File tree

5 files changed

+197
-138
lines changed

5 files changed

+197
-138
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This source code is dual-licensed under the Apache License, version 2.0,
2+
// and the Mozilla Public License, version 2.0.
3+
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
5+
using System;
6+
7+
namespace RabbitMQ.AMQP.Client
8+
{
9+
/// <summary>
10+
/// Exception related to <see cref="IConnection"/>
11+
/// </summary>
12+
public class ConnectionException : Exception
13+
{
14+
/// <summary>
15+
/// Create a <see cref="ConnectionException"/> with the specified message.
16+
/// </summary>
17+
public ConnectionException(string message) : base(message)
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Create a <see cref="ConnectionException"/> with the specified message and inner <see cref="Exception"/>.
23+
/// </summary>
24+
public ConnectionException(string message, Exception innerException) : base(message, innerException)
25+
{
26+
}
27+
}
28+
}

RabbitMQ.AMQP.Client/IConnection.cs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,60 @@
22
// and the Mozilla Public License, version 2.0.
33
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
44

5-
using System;
65
using System.Collections.Generic;
76

87
namespace RabbitMQ.AMQP.Client
98
{
10-
public class ConnectionException : Exception
11-
{
12-
public ConnectionException(string message) : base(message)
13-
{
14-
}
15-
16-
public ConnectionException(string message, Exception innerException) : base(message, innerException)
17-
{
18-
}
19-
}
20-
219
public interface IConnection : ILifeCycle
2210
{
11+
/// <summary>
12+
/// The <see cref="IManagement"/> instance for this connection.
13+
/// </summary>
14+
/// <returns><see cref="IManagement"/> instance for this connection.</returns>
2315
IManagement Management();
2416

17+
/// <summary>
18+
/// Create an <see cref="IPublisherBuilder"/> instance for this connection.
19+
/// </summary>
20+
/// <returns><see cref="IPublisherBuilder"/> instance for this connection.</returns>
2521
IPublisherBuilder PublisherBuilder();
2622

23+
/// <summary>
24+
/// Create an <see cref="IConsumerBuilder"/> instance for this connection.
25+
/// </summary>
26+
/// <returns><see cref="IConsumerBuilder"/> instance for this connection.</returns>
2727
IConsumerBuilder ConsumerBuilder();
2828

29+
/// <summary>
30+
/// Create an <see cref="IRpcServerBuilder"/> instance for this connection.
31+
/// </summary>
32+
/// <returns><see cref="IRpcServerBuilder"/> instance for this connection.</returns>
2933
IRpcServerBuilder RpcServerBuilder();
3034

35+
/// <summary>
36+
/// Create an <see cref="IRpcClientBuilder"/> instance for this connection.
37+
/// </summary>
38+
/// <returns><see cref="IRpcClientBuilder"/> instance for this connection.</returns>
3139
IRpcClientBuilder RpcClientBuilder();
3240

41+
/// <summary>
42+
/// Get the properties for this connection.
43+
/// </summary>
3344
public IReadOnlyDictionary<string, object> Properties { get; }
3445

46+
/// <summary>
47+
/// Get the <see cref="IPublisher"/> instances associated with this connection.
48+
/// </summary>
3549
public IEnumerable<IPublisher> Publishers { get; }
3650

51+
/// <summary>
52+
/// Get the <see cref="IConsumer"/> instances associated with this connection.
53+
/// </summary>
3754
public IEnumerable<IConsumer> Consumers { get; }
3855

56+
/// <summary>
57+
/// Get or set the Connection ID
58+
/// </summary>
3959
public long Id { get; set; }
4060
}
4161
}

RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs

Lines changed: 52 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public class AmqpConnection : AbstractLifeCycle, IConnection
3737
private readonly ConnectionSettings _connectionSettings;
3838
private readonly IMetricsReporter? _metricsReporter;
3939

40-
// TODO this is coupled with publishers and consumers
41-
internal readonly AmqpSessionManagement _nativePubSubSessions;
42-
4340
private readonly Dictionary<string, object> _connectionProperties = new();
4441
private bool _areFilterExpressionsSupported = false;
4542

@@ -59,47 +56,12 @@ public class AmqpConnection : AbstractLifeCycle, IConnection
5956
/// </summary>
6057
private readonly ConcurrentDictionary<Guid, IConsumer> _consumersDict = new();
6158

62-
// TODO this couples AmqpConnection with AmqpPublisher, yuck
63-
internal void AddPublisher(Guid id, IPublisher consumer)
64-
{
65-
if (false == _publishersDict.TryAdd(id, consumer))
66-
{
67-
// TODO create "internal bug" exception type?
68-
throw new InvalidOperationException("could not add publisher, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
69-
}
70-
}
71-
72-
internal void RemovePublisher(Guid id)
73-
{
74-
if (false == _publishersDict.TryRemove(id, out _))
75-
{
76-
// TODO create "internal bug" exception type?
77-
throw new InvalidOperationException("could not remove publisher, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
78-
}
79-
}
80-
81-
// TODO this couples AmqpConnection with AmqpConsumer, yuck
82-
internal void AddConsumer(Guid id, IConsumer consumer)
83-
{
84-
if (false == _consumersDict.TryAdd(id, consumer))
85-
{
86-
// TODO create "internal bug" exception type?
87-
throw new InvalidOperationException("could not add consumer, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
88-
}
89-
}
90-
91-
internal void RemoveConsumer(Guid id)
92-
{
93-
if (false == _consumersDict.TryRemove(id, out _))
94-
{
95-
// TODO create "internal bug" exception type?
96-
throw new InvalidOperationException("could not remove consumer, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
97-
}
98-
}
99-
10059
private readonly TaskCompletionSource<bool> _connectionClosedTcs =
10160
Utils.CreateTaskCompletionSource<bool>();
10261

62+
// TODO this is coupled with publishers and consumers
63+
internal readonly AmqpSessionManagement _nativePubSubSessions;
64+
10365
public IRpcServerBuilder RpcServerBuilder()
10466
{
10567
return new AmqpRpcServerBuilder(this);
@@ -164,6 +126,13 @@ public IConsumerBuilder ConsumerBuilder()
164126
return new AmqpConsumerBuilder(this, _metricsReporter);
165127
}
166128

129+
public IPublisherBuilder PublisherBuilder()
130+
{
131+
ThrowIfClosed();
132+
var publisherBuilder = new AmqpPublisherBuilder(this, _metricsReporter);
133+
return publisherBuilder;
134+
}
135+
167136
// TODO cancellation token
168137
public override async Task OpenAsync()
169138
{
@@ -174,13 +143,6 @@ await base.OpenAsync()
174143
.ConfigureAwait(false);
175144
}
176145

177-
public IPublisherBuilder PublisherBuilder()
178-
{
179-
ThrowIfClosed();
180-
var publisherBuilder = new AmqpPublisherBuilder(this, _metricsReporter);
181-
return publisherBuilder;
182-
}
183-
184146
public override async Task CloseAsync()
185147
{
186148
await _semaphoreClose.WaitAsync()
@@ -229,10 +191,6 @@ public override string ToString()
229191
return info;
230192
}
231193

232-
internal Connection? NativeConnection => _nativeConnection;
233-
234-
internal bool AreFilterExpressionsSupported => _areFilterExpressionsSupported;
235-
236194
protected override void Dispose(bool disposing)
237195
{
238196
if (disposing)
@@ -250,6 +208,48 @@ protected override void Dispose(bool disposing)
250208
base.Dispose(disposing);
251209
}
252210

211+
internal Connection? NativeConnection => _nativeConnection;
212+
213+
internal bool AreFilterExpressionsSupported => _areFilterExpressionsSupported;
214+
215+
// TODO this couples AmqpConnection with AmqpPublisher, yuck
216+
internal void AddPublisher(Guid id, IPublisher consumer)
217+
{
218+
if (false == _publishersDict.TryAdd(id, consumer))
219+
{
220+
// TODO create "internal bug" exception type?
221+
throw new InvalidOperationException("could not add publisher, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
222+
}
223+
}
224+
225+
internal void RemovePublisher(Guid id)
226+
{
227+
if (false == _publishersDict.TryRemove(id, out _))
228+
{
229+
// TODO create "internal bug" exception type?
230+
throw new InvalidOperationException("could not remove publisher, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
231+
}
232+
}
233+
234+
// TODO this couples AmqpConnection with AmqpConsumer, yuck
235+
internal void AddConsumer(Guid id, IConsumer consumer)
236+
{
237+
if (false == _consumersDict.TryAdd(id, consumer))
238+
{
239+
// TODO create "internal bug" exception type?
240+
throw new InvalidOperationException("could not add consumer, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
241+
}
242+
}
243+
244+
internal void RemoveConsumer(Guid id)
245+
{
246+
if (false == _consumersDict.TryRemove(id, out _))
247+
{
248+
// TODO create "internal bug" exception type?
249+
throw new InvalidOperationException("could not remove consumer, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues");
250+
}
251+
}
252+
253253
/// <summary>
254254
/// Closes all the publishers. It is called when the connection is closed.
255255
/// </summary>
@@ -619,71 +619,4 @@ private void HandleProperties(Fields properties)
619619
_areFilterExpressionsSupported = Utils.SupportsFilterExpressions(brokerVersion);
620620
}
621621
}
622-
623-
internal class Visitor : IVisitor
624-
{
625-
private readonly AmqpManagement _management;
626-
627-
internal Visitor(AmqpManagement management)
628-
{
629-
_management = management;
630-
}
631-
632-
public async Task VisitQueuesAsync(IEnumerable<QueueSpec> queueSpec)
633-
{
634-
// TODO this could be done in parallel
635-
foreach (QueueSpec spec in queueSpec)
636-
{
637-
Trace.WriteLine(TraceLevel.Information, $"Recovering queue {spec.QueueName}");
638-
try
639-
{
640-
await _management.Queue(spec).DeclareAsync()
641-
.ConfigureAwait(false);
642-
}
643-
catch (Exception e)
644-
{
645-
Trace.WriteLine(TraceLevel.Error,
646-
$"Error recovering queue {spec.QueueName}. Error: {e}. Management Status: {_management}");
647-
}
648-
}
649-
}
650-
651-
public async Task VisitExchangesAsync(IEnumerable<ExchangeSpec> exchangeSpec)
652-
{
653-
// TODO this could be done in parallel
654-
foreach (ExchangeSpec spec in exchangeSpec)
655-
{
656-
Trace.WriteLine(TraceLevel.Information, $"Recovering exchange {spec.ExchangeName}");
657-
try
658-
{
659-
await _management.Exchange(spec).DeclareAsync()
660-
.ConfigureAwait(false);
661-
}
662-
catch (Exception e)
663-
{
664-
Trace.WriteLine(TraceLevel.Error,
665-
$"Error recovering exchange {spec.ExchangeName}. Error: {e}. Management Status: {_management}");
666-
}
667-
}
668-
}
669-
670-
public async Task VisitBindingsAsync(IEnumerable<BindingSpec> bindingSpec)
671-
{
672-
// TODO this could be done in parallel
673-
foreach (BindingSpec spec in bindingSpec)
674-
{
675-
Trace.WriteLine(TraceLevel.Information, $"Recovering binding {spec.BindingPath}");
676-
try
677-
{
678-
await _management.Binding(spec).BindAsync()
679-
.ConfigureAwait(false);
680-
}
681-
catch (Exception e)
682-
{
683-
Trace.WriteLine(TraceLevel.Error,
684-
$"Error recovering binding {spec.BindingPath}. Error: {e}. Management Status: {_management}");
685-
}
686-
}
687-
}
688-
}
689622
}

RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
namespace RabbitMQ.AMQP.Client.Impl
1010
{
11-
internal interface IVisitor
12-
{
13-
Task VisitQueuesAsync(IEnumerable<QueueSpec> queueSpec);
14-
Task VisitExchangesAsync(IEnumerable<ExchangeSpec> exchangeSpec);
15-
Task VisitBindingsAsync(IEnumerable<BindingSpec> bindingSpec);
16-
}
17-
1811
/// <summary>
1912
/// RecordingTopologyListener is a concrete implementation of <see cref="ITopologyListener"/>
2013
/// It is used to record the topology of the entities declared in the AMQP server ( like queues, exchanges, etc)

0 commit comments

Comments
 (0)