Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exchange type to be a string #75

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RabbitMQ.AMQP.Client/IEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ public interface IExchangeSpecification : IEntitySpecification
bool IsAutoDelete { get; }
IExchangeSpecification AutoDelete(bool isAutoDelete);

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

Dictionary<string, object> ExchangeArguments { get; }
IExchangeSpecification Argument(string key, object value);
Expand Down
16 changes: 11 additions & 5 deletions RabbitMQ.AMQP.Client/Impl/AmqpExchangeSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AmqpExchangeSpecification(AmqpManagement management)

private string _name = "";
private bool _autoDelete;
private ExchangeType _type = Client.ExchangeType.DIRECT;
private string _exchangeType = Client.ExchangeType.DIRECT.ToString();
private readonly Map _arguments = new();

public Task DeclareAsync()
Expand All @@ -36,7 +36,7 @@ public Task DeclareAsync()
{
{ "auto_delete", _autoDelete },
{ "arguments", _arguments },
{ "type", _type.ToString().ToLower() },
{ "type", _exchangeType.ToLowerInvariant() },
{ "durable", true }
};

Expand Down Expand Up @@ -75,13 +75,19 @@ public IExchangeSpecification AutoDelete(bool autoDelete)

public bool IsAutoDelete => _autoDelete;

public IExchangeSpecification Type(ExchangeType type)
public IExchangeSpecification Type(ExchangeType exchangeType)
{
_type = type;
_exchangeType = exchangeType.ToString();
return this;
}

public ExchangeType ExchangeType => _type;
public IExchangeSpecification Type(string exchangeType)
{
_exchangeType = exchangeType;
return this;
}

public string ExchangeType => _exchangeType;

public IExchangeSpecification Argument(string key, object value)
{
Expand Down
2 changes: 1 addition & 1 deletion RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal ExchangeSpec(IExchangeSpecification exchangeSpecification)

internal string ExchangeName => _exchangeSpecification.ExchangeName;

internal ExchangeType ExchangeType => _exchangeSpecification.ExchangeType;
internal string ExchangeType => _exchangeSpecification.ExchangeType;

internal bool IsAutoDelete => _exchangeSpecification.IsAutoDelete;

Expand Down
8 changes: 5 additions & 3 deletions RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ RabbitMQ.AMQP.Client.IExchangeSpecification.Arguments(System.Collections.Generic
RabbitMQ.AMQP.Client.IExchangeSpecification.AutoDelete(bool isAutoDelete) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.IExchangeSpecification.ExchangeArguments.get -> System.Collections.Generic.Dictionary<string!, object!>!
RabbitMQ.AMQP.Client.IExchangeSpecification.ExchangeName.get -> string!
RabbitMQ.AMQP.Client.IExchangeSpecification.ExchangeType.get -> RabbitMQ.AMQP.Client.ExchangeType
RabbitMQ.AMQP.Client.IExchangeSpecification.ExchangeType.get -> string!
RabbitMQ.AMQP.Client.IExchangeSpecification.IsAutoDelete.get -> bool
RabbitMQ.AMQP.Client.IExchangeSpecification.Name(string! exchangeName) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.IExchangeSpecification.Type(RabbitMQ.AMQP.Client.ExchangeType exchangeType) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.IExchangeSpecification.Type(string! exchangeType) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.ILifeCycle
RabbitMQ.AMQP.Client.ILifeCycle.ChangeState -> RabbitMQ.AMQP.Client.LifeCycleCallBack!
RabbitMQ.AMQP.Client.ILifeCycle.CloseAsync() -> System.Threading.Tasks.Task!
Expand Down Expand Up @@ -262,10 +263,11 @@ RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.DeclareAsync() -> System.Thr
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.DeleteAsync() -> System.Threading.Tasks.Task!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.ExchangeArguments.get -> System.Collections.Generic.Dictionary<string!, object!>!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.ExchangeName.get -> string!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.ExchangeType.get -> RabbitMQ.AMQP.Client.ExchangeType
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.ExchangeType.get -> string!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.IsAutoDelete.get -> bool
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.Name(string! name) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.Type(RabbitMQ.AMQP.Client.ExchangeType type) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.Type(RabbitMQ.AMQP.Client.ExchangeType exchangeType) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.Impl.AmqpExchangeSpecification.Type(string! exchangeType) -> RabbitMQ.AMQP.Client.IExchangeSpecification!
RabbitMQ.AMQP.Client.Impl.AmqpManagement
RabbitMQ.AMQP.Client.Impl.AmqpManagement.Binding() -> RabbitMQ.AMQP.Client.IBindingSpecification!
RabbitMQ.AMQP.Client.Impl.AmqpManagement.Exchange() -> RabbitMQ.AMQP.Client.IExchangeSpecification!
Expand Down
18 changes: 18 additions & 0 deletions Tests/Management/ManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ public async Task SimpleDeclareAndDeleteExchangeWithName()
await SystemUtils.WaitUntilExchangeDeletedAsync(exchangeSpec);
}

[Fact]
public async Task DeclareAndDeleteExchangeWithStringType()
{
Assert.NotNull(_connection);
Assert.NotNull(_management);

IExchangeSpecification exchangeSpec = _management.Exchange(_exchangeName).Type("direct");
await exchangeSpec.DeclareAsync();

await _management.Exchange(_exchangeName).Type("direct").DeclareAsync();

await SystemUtils.WaitUntilExchangeExistsAsync(exchangeSpec);

await exchangeSpec.DeleteAsync();

await SystemUtils.WaitUntilExchangeDeletedAsync(exchangeSpec);
}

[Fact]
public async Task ExchangeWithEmptyNameShouldRaiseAnException()
{
Expand Down