Skip to content

Commit 7faf7e0

Browse files
authored
Merge pull request #54 from rabbitmq/lukebakken/dotnet-ify-api
Make public API more dotnet-ish
2 parents 131b6b8 + d8d8c43 commit 7faf7e0

23 files changed

+345
-311
lines changed

.github/workflows/build-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: ${{ github.workspace }}/.ci/ubuntu/gha-setup.sh
6666
- name: Test
6767
timeout-minutes: 15
68-
run: dotnet test ${{ github.workspace }}/Build.csproj --no-restore --no-build --logger "console;verbosity=detailed" /p:AltCover=true /p:AltCoverStrongNameKey=${{github.workspace}}/rabbit.snk
68+
run: dotnet test ${{ github.workspace }}/Build.csproj --no-restore --no-build --logger "console;verbosity=detailed"
6969
- name: Check for errors in RabbitMQ logs
7070
run: ${{ github.workspace}}/.ci/ubuntu/gha-log-check.sh
7171
- name: Maybe upload RabbitMQ logs

Directory.Packages.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
5+
56
<ItemGroup>
67
<!-- RabbitMQ.Amqp.Client -->
78
<PackageVersion Include="AMQPNetLite.Core" Version="2.4.11" />
89
<!-- Tests -->
9-
<PackageVersion Include="AltCover" Version="8.9.3" />
1010
<PackageVersion Include="xunit" Version="2.9.0" />
1111
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
1212
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
1313
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
1414
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
1515
<PackageVersion Include="EasyNetQ.Management.Client" Version="3.0.0" />
1616
</ItemGroup>
17+
1718
<ItemGroup Condition="$(TargetFramework)=='netstandard2.0'">
1819
<!--
1920
Note: do NOT upgrade these dependencies unless necessary
@@ -24,15 +25,19 @@
2425
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
2526
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
2627
</ItemGroup>
28+
2729
<ItemGroup Condition="'$(TargetFramework)'=='net6.0'">
2830
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
2931
</ItemGroup>
32+
3033
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
3134
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
3235
</ItemGroup>
36+
3337
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
3438
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
3539
</ItemGroup>
40+
3641
<ItemGroup Condition="'$(IsPackable)'=='true'">
3742
<GlobalPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
3843
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build:
77
dotnet build $(CURDIR)/Build.csproj
88

99
test: build
10-
dotnet test -c Debug $(CURDIR)/Tests/Tests.csproj --no-build --logger:"console;verbosity=detailed" /p:AltCover=true /p:AltCoverStrongNameKey=$(CURDIR)/rabbit.snk
10+
dotnet test -c Debug $(CURDIR)/Tests/Tests.csproj --no-build --logger:"console;verbosity=detailed"
1111

1212
rabbitmq-server-start-arm:
1313
./.ci/ubuntu/gha-setup.sh start pull arm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This library is in early stages of development. It is meant to be used with Rabb
55
## How to Run
66

77
- Start the broker with `./.ci/ubuntu/gha-setup.sh start`. Note that this has been tested on Ubuntu 22 with docker.
8-
- Run the tests with ` dotnet test ./Build.csproj --logger "console;verbosity=detailed" /p:AltCover=true`
8+
- Run the tests with ` dotnet test ./Build.csproj --logger "console;verbosity=detailed"`
99
- Stop RabbitMQ with `./.ci/ubuntu/gha-setup.sh stop`
1010

1111
## Getting Started

RabbitMQ.AMQP.Client/IEntities.cs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ public enum OverFlowStrategy
4444

4545
public interface IQueueSpecification : IEntityInfoSpecification<IQueueInfo>
4646
{
47-
public string Name();
48-
IQueueSpecification Name(string name);
47+
public string QueueName { get; }
48+
IQueueSpecification Name(string queueName);
4949

50-
public bool Exclusive();
51-
IQueueSpecification Exclusive(bool exclusive);
50+
public bool IsExclusive { get; }
51+
IQueueSpecification Exclusive(bool isExclusive);
5252

53-
public bool AutoDelete();
54-
IQueueSpecification AutoDelete(bool autoDelete);
53+
public bool IsAutoDelete { get; }
54+
IQueueSpecification AutoDelete(bool isAutoDelete);
5555

56-
public Dictionary<object, object> Arguments();
57-
IQueueSpecification Arguments(Dictionary<object, object> arguments);
56+
public Dictionary<object, object> QueueArguments { get; }
57+
IQueueSpecification Arguments(Dictionary<object, object> queueArguments);
5858

59-
public QueueType Type();
60-
IQueueSpecification Type(QueueType type);
59+
public QueueType QueueType { get; }
60+
IQueueSpecification Type(QueueType queueType);
6161

6262
IQueueSpecification DeadLetterExchange(string dlx);
6363

@@ -71,15 +71,15 @@ public interface IQueueSpecification : IEntityInfoSpecification<IQueueInfo>
7171

7272
IQueueSpecification Expires(TimeSpan expiration);
7373

74+
IQueueSpecification MaxLength(long maxLength);
75+
76+
IQueueSpecification MessageTtl(TimeSpan ttl);
77+
7478
IStreamSpecification Stream();
7579

7680
IQuorumQueueSpecification Quorum();
7781

7882
IClassicQueueSpecification Classic();
79-
80-
IQueueSpecification MaxLength(long maxLength);
81-
82-
IQueueSpecification MessageTtl(TimeSpan ttl);
8383
}
8484

8585
public interface IStreamSpecification
@@ -140,47 +140,43 @@ public interface IClassicQueueSpecification
140140

141141
public interface IExchangeSpecification : IEntitySpecification
142142
{
143-
string Name();
144-
IExchangeSpecification Name(string name);
145-
146-
IExchangeSpecification AutoDelete(bool autoDelete);
143+
string ExchangeName { get; }
144+
IExchangeSpecification Name(string exchangeName);
147145

148-
bool AutoDelete();
146+
bool IsAutoDelete { get; }
147+
IExchangeSpecification AutoDelete(bool isAutoDelete);
149148

150-
IExchangeSpecification Type(ExchangeType type);
151-
152-
ExchangeType Type();
149+
ExchangeType ExchangeType { get; }
150+
IExchangeSpecification Type(ExchangeType exchangeType);
153151

152+
Dictionary<string, object> ExchangeArguments { get; }
154153
IExchangeSpecification Argument(string key, object value);
155-
Dictionary<string, object> Arguments();
156-
157154
IExchangeSpecification Arguments(Dictionary<string, object> arguments);
158155
}
159156

160157
public interface IBindingSpecification
161158
{
162159
IBindingSpecification SourceExchange(IExchangeSpecification exchangeSpec);
163160

161+
string SourceExchangeName { get; }
164162
IBindingSpecification SourceExchange(string exchangeName);
165-
string SourceExchangeName();
166163

164+
string DestinationQueueName { get; }
167165
IBindingSpecification DestinationQueue(IQueueSpecification queueSpec);
168166
IBindingSpecification DestinationQueue(string queueName);
169-
string DestinationQueueName();
170167

168+
string DestinationExchangeName { get; }
171169
IBindingSpecification DestinationExchange(IExchangeSpecification exchangeSpec);
172170
IBindingSpecification DestinationExchange(string exchangeName);
173-
string DestinationExchangeName();
174171

175-
IBindingSpecification Key(string key);
176-
string Key();
172+
string BindingKey { get; }
173+
IBindingSpecification Key(string bindingKey);
177174

175+
Dictionary<string, object> BindingArguments { get; }
178176
IBindingSpecification Argument(string key, object value);
179-
180177
IBindingSpecification Arguments(Dictionary<string, object> arguments);
181-
Dictionary<string, object> Arguments();
182178

183-
string Path();
179+
string BindingPath { get; }
184180

185181
Task BindAsync();
186182
Task UnbindAsync();

RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace RabbitMQ.AMQP.Client.Impl
1010
{
1111
public abstract class BindingSpecification
1212
{
13-
protected string _source = "";
14-
protected string _destination = "";
13+
protected string _sourceName = "";
14+
protected string _destinationName = "";
1515
protected string _routingKey = "";
1616
protected bool _toQueue = true;
1717
protected Dictionary<string, object> _arguments = new();
@@ -41,21 +41,22 @@ public AmqpBindingSpecification(AmqpManagement management)
4141
_topologyListener = ((IManagementTopology)_management).TopologyListener();
4242
}
4343

44-
public Dictionary<string, object> Arguments()
44+
public string BindingPath
4545
{
46-
return _arguments;
46+
get
47+
{
48+
return BindingsTarget();
49+
}
4750
}
4851

49-
public string Path() => BindingsTarget();
50-
5152
public async Task BindAsync()
5253
{
5354
var kv = new Map
5455
{
55-
{ "source", _source },
56+
{ "source", _sourceName },
5657
{ "binding_key", _routingKey },
5758
{ "arguments", ArgsToMap() },
58-
{ _toQueue ? "destination_queue" : "destination_exchange", _destination }
59+
{ _toQueue ? "destination_queue" : "destination_exchange", _destinationName }
5960
};
6061

6162
string path = $"/{Consts.Bindings}";
@@ -78,9 +79,9 @@ public async Task UnbindAsync()
7879
if (_arguments.Count == 0)
7980
{
8081
string path =
81-
$"/{Consts.Bindings}/src={Utils.EncodePathSegment(_source)};{($"{destinationCharacter}={Utils.EncodePathSegment(_destination)};key={Utils.EncodePathSegment(_routingKey)};args=")}";
82+
$"/{Consts.Bindings}/src={Utils.EncodePathSegment(_sourceName)};{($"{destinationCharacter}={Utils.EncodePathSegment(_destinationName)};key={Utils.EncodePathSegment(_routingKey)};args=")}";
8283

83-
_topologyListener.BindingDeleted(Path());
84+
_topologyListener.BindingDeleted(BindingPath);
8485
await _management.RequestAsync(null, path, method, expectedReturnCodes)
8586
.ConfigureAwait(false);
8687
}
@@ -104,55 +105,76 @@ await _management.RequestAsync(null, path, method, expectedReturnCodes)
104105

105106
public IBindingSpecification SourceExchange(IExchangeSpecification exchangeSpec)
106107
{
107-
return SourceExchange(exchangeSpec.Name());
108+
return SourceExchange(exchangeSpec.ExchangeName);
108109
}
109110

110111
public IBindingSpecification SourceExchange(string exchangeName)
111112
{
112113
_toQueue = false;
113-
_source = exchangeName;
114+
_sourceName = exchangeName;
114115
return this;
115116
}
116117

117-
public string SourceExchangeName()
118+
public string SourceExchangeName
118119
{
119-
return _source;
120+
get
121+
{
122+
return _sourceName;
123+
}
120124
}
121125

122126
public IBindingSpecification DestinationQueue(IQueueSpecification queueSpec)
123127
{
124-
return DestinationQueue(queueSpec.Name());
128+
return DestinationQueue(queueSpec.QueueName);
125129
}
126130

127131
public IBindingSpecification DestinationQueue(string queueName)
128132
{
129133
_toQueue = true;
130-
_destination = queueName;
134+
_destinationName = queueName;
131135
return this;
132136
}
133137

134-
public string DestinationQueueName() => _destination;
138+
public string DestinationQueueName
139+
{
140+
get
141+
{
142+
return _destinationName;
143+
}
144+
}
135145

136146
public IBindingSpecification DestinationExchange(IExchangeSpecification exchangeSpec)
137147
{
138-
return DestinationExchange(exchangeSpec.Name());
148+
return DestinationExchange(exchangeSpec.ExchangeName);
139149
}
140150

141151
public IBindingSpecification DestinationExchange(string exchangeName)
142152
{
143-
_destination = exchangeName;
153+
_destinationName = exchangeName;
144154
return this;
145155
}
146156

147-
public string DestinationExchangeName() => _destination;
157+
public string DestinationExchangeName
158+
{
159+
get
160+
{
161+
return _destinationName;
162+
}
163+
}
148164

149-
public IBindingSpecification Key(string key)
165+
public IBindingSpecification Key(string bindingKey)
150166
{
151-
_routingKey = key;
167+
_routingKey = bindingKey;
152168
return this;
153169
}
154170

155-
public string Key() => _routingKey;
171+
public string BindingKey
172+
{
173+
get
174+
{
175+
return _routingKey;
176+
}
177+
}
156178

157179
public IBindingSpecification Argument(string key, object value)
158180
{
@@ -166,15 +188,23 @@ public IBindingSpecification Arguments(Dictionary<string, object> arguments)
166188
return this;
167189
}
168190

191+
public Dictionary<string, object> BindingArguments
192+
{
193+
get
194+
{
195+
return _arguments;
196+
}
197+
}
198+
169199
private string BindingsTarget()
170200
{
171201
string destinationField = _toQueue ? "dstq" : "dste";
172202
return "/bindings?src="
173-
+ Utils.EncodeHttpParameter(_source)
203+
+ Utils.EncodeHttpParameter(_sourceName)
174204
+ "&"
175205
+ destinationField
176206
+ "="
177-
+ Utils.EncodeHttpParameter(_destination)
207+
+ Utils.EncodeHttpParameter(_destinationName)
178208
+ "&key="
179209
+ Utils.EncodeHttpParameter(_routingKey);
180210
}

0 commit comments

Comments
 (0)