Skip to content

Commit

Permalink
Merge pull request #54 from rabbitmq/lukebakken/dotnet-ify-api
Browse files Browse the repository at this point in the history
Make public API more dotnet-ish
  • Loading branch information
lukebakken committed Aug 28, 2024
2 parents 131b6b8 + d8d8c43 commit 7faf7e0
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 311 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
run: ${{ github.workspace }}/.ci/ubuntu/gha-setup.sh
- name: Test
timeout-minutes: 15
run: dotnet test ${{ github.workspace }}/Build.csproj --no-restore --no-build --logger "console;verbosity=detailed" /p:AltCover=true /p:AltCoverStrongNameKey=${{github.workspace}}/rabbit.snk
run: dotnet test ${{ github.workspace }}/Build.csproj --no-restore --no-build --logger "console;verbosity=detailed"
- name: Check for errors in RabbitMQ logs
run: ${{ github.workspace}}/.ci/ubuntu/gha-log-check.sh
- name: Maybe upload RabbitMQ logs
Expand Down
7 changes: 6 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<!-- RabbitMQ.Amqp.Client -->
<PackageVersion Include="AMQPNetLite.Core" Version="2.4.11" />
<!-- Tests -->
<PackageVersion Include="AltCover" Version="8.9.3" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageVersion Include="EasyNetQ.Management.Client" Version="3.0.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework)=='netstandard2.0'">
<!--
Note: do NOT upgrade these dependencies unless necessary
Expand All @@ -24,15 +25,19 @@
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net6.0'">
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>

<ItemGroup Condition="'$(IsPackable)'=='true'">
<GlobalPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:
dotnet build $(CURDIR)/Build.csproj

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

rabbitmq-server-start-arm:
./.ci/ubuntu/gha-setup.sh start pull arm
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library is in early stages of development. It is meant to be used with Rabb
## How to Run

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

## Getting Started
Expand Down
60 changes: 28 additions & 32 deletions RabbitMQ.AMQP.Client/IEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public enum OverFlowStrategy

public interface IQueueSpecification : IEntityInfoSpecification<IQueueInfo>
{
public string Name();
IQueueSpecification Name(string name);
public string QueueName { get; }
IQueueSpecification Name(string queueName);

public bool Exclusive();
IQueueSpecification Exclusive(bool exclusive);
public bool IsExclusive { get; }
IQueueSpecification Exclusive(bool isExclusive);

public bool AutoDelete();
IQueueSpecification AutoDelete(bool autoDelete);
public bool IsAutoDelete { get; }
IQueueSpecification AutoDelete(bool isAutoDelete);

public Dictionary<object, object> Arguments();
IQueueSpecification Arguments(Dictionary<object, object> arguments);
public Dictionary<object, object> QueueArguments { get; }
IQueueSpecification Arguments(Dictionary<object, object> queueArguments);

public QueueType Type();
IQueueSpecification Type(QueueType type);
public QueueType QueueType { get; }
IQueueSpecification Type(QueueType queueType);

IQueueSpecification DeadLetterExchange(string dlx);

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

IQueueSpecification Expires(TimeSpan expiration);

IQueueSpecification MaxLength(long maxLength);

IQueueSpecification MessageTtl(TimeSpan ttl);

IStreamSpecification Stream();

IQuorumQueueSpecification Quorum();

IClassicQueueSpecification Classic();

IQueueSpecification MaxLength(long maxLength);

IQueueSpecification MessageTtl(TimeSpan ttl);
}

public interface IStreamSpecification
Expand Down Expand Up @@ -140,47 +140,43 @@ public interface IClassicQueueSpecification

public interface IExchangeSpecification : IEntitySpecification
{
string Name();
IExchangeSpecification Name(string name);

IExchangeSpecification AutoDelete(bool autoDelete);
string ExchangeName { get; }
IExchangeSpecification Name(string exchangeName);

bool AutoDelete();
bool IsAutoDelete { get; }
IExchangeSpecification AutoDelete(bool isAutoDelete);

IExchangeSpecification Type(ExchangeType type);

ExchangeType Type();
ExchangeType ExchangeType { get; }
IExchangeSpecification Type(ExchangeType exchangeType);

Dictionary<string, object> ExchangeArguments { get; }
IExchangeSpecification Argument(string key, object value);
Dictionary<string, object> Arguments();

IExchangeSpecification Arguments(Dictionary<string, object> arguments);
}

public interface IBindingSpecification
{
IBindingSpecification SourceExchange(IExchangeSpecification exchangeSpec);

string SourceExchangeName { get; }
IBindingSpecification SourceExchange(string exchangeName);
string SourceExchangeName();

string DestinationQueueName { get; }
IBindingSpecification DestinationQueue(IQueueSpecification queueSpec);
IBindingSpecification DestinationQueue(string queueName);
string DestinationQueueName();

string DestinationExchangeName { get; }
IBindingSpecification DestinationExchange(IExchangeSpecification exchangeSpec);
IBindingSpecification DestinationExchange(string exchangeName);
string DestinationExchangeName();

IBindingSpecification Key(string key);
string Key();
string BindingKey { get; }
IBindingSpecification Key(string bindingKey);

Dictionary<string, object> BindingArguments { get; }
IBindingSpecification Argument(string key, object value);

IBindingSpecification Arguments(Dictionary<string, object> arguments);
Dictionary<string, object> Arguments();

string Path();
string BindingPath { get; }

Task BindAsync();
Task UnbindAsync();
Expand Down
80 changes: 55 additions & 25 deletions RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace RabbitMQ.AMQP.Client.Impl
{
public abstract class BindingSpecification
{
protected string _source = "";
protected string _destination = "";
protected string _sourceName = "";
protected string _destinationName = "";
protected string _routingKey = "";
protected bool _toQueue = true;
protected Dictionary<string, object> _arguments = new();
Expand Down Expand Up @@ -41,21 +41,22 @@ public AmqpBindingSpecification(AmqpManagement management)
_topologyListener = ((IManagementTopology)_management).TopologyListener();
}

public Dictionary<string, object> Arguments()
public string BindingPath
{
return _arguments;
get
{
return BindingsTarget();
}
}

public string Path() => BindingsTarget();

public async Task BindAsync()
{
var kv = new Map
{
{ "source", _source },
{ "source", _sourceName },
{ "binding_key", _routingKey },
{ "arguments", ArgsToMap() },
{ _toQueue ? "destination_queue" : "destination_exchange", _destination }
{ _toQueue ? "destination_queue" : "destination_exchange", _destinationName }
};

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

_topologyListener.BindingDeleted(Path());
_topologyListener.BindingDeleted(BindingPath);
await _management.RequestAsync(null, path, method, expectedReturnCodes)
.ConfigureAwait(false);
}
Expand All @@ -104,55 +105,76 @@ await _management.RequestAsync(null, path, method, expectedReturnCodes)

public IBindingSpecification SourceExchange(IExchangeSpecification exchangeSpec)
{
return SourceExchange(exchangeSpec.Name());
return SourceExchange(exchangeSpec.ExchangeName);
}

public IBindingSpecification SourceExchange(string exchangeName)
{
_toQueue = false;
_source = exchangeName;
_sourceName = exchangeName;
return this;
}

public string SourceExchangeName()
public string SourceExchangeName
{
return _source;
get
{
return _sourceName;
}
}

public IBindingSpecification DestinationQueue(IQueueSpecification queueSpec)
{
return DestinationQueue(queueSpec.Name());
return DestinationQueue(queueSpec.QueueName);
}

public IBindingSpecification DestinationQueue(string queueName)
{
_toQueue = true;
_destination = queueName;
_destinationName = queueName;
return this;
}

public string DestinationQueueName() => _destination;
public string DestinationQueueName
{
get
{
return _destinationName;
}
}

public IBindingSpecification DestinationExchange(IExchangeSpecification exchangeSpec)
{
return DestinationExchange(exchangeSpec.Name());
return DestinationExchange(exchangeSpec.ExchangeName);
}

public IBindingSpecification DestinationExchange(string exchangeName)
{
_destination = exchangeName;
_destinationName = exchangeName;
return this;
}

public string DestinationExchangeName() => _destination;
public string DestinationExchangeName
{
get
{
return _destinationName;
}
}

public IBindingSpecification Key(string key)
public IBindingSpecification Key(string bindingKey)
{
_routingKey = key;
_routingKey = bindingKey;
return this;
}

public string Key() => _routingKey;
public string BindingKey
{
get
{
return _routingKey;
}
}

public IBindingSpecification Argument(string key, object value)
{
Expand All @@ -166,15 +188,23 @@ public IBindingSpecification Arguments(Dictionary<string, object> arguments)
return this;
}

public Dictionary<string, object> BindingArguments
{
get
{
return _arguments;
}
}

private string BindingsTarget()
{
string destinationField = _toQueue ? "dstq" : "dste";
return "/bindings?src="
+ Utils.EncodeHttpParameter(_source)
+ Utils.EncodeHttpParameter(_sourceName)
+ "&"
+ destinationField
+ "="
+ Utils.EncodeHttpParameter(_destination)
+ Utils.EncodeHttpParameter(_destinationName)
+ "&key="
+ Utils.EncodeHttpParameter(_routingKey);
}
Expand Down
Loading

0 comments on commit 7faf7e0

Please sign in to comment.