Skip to content

Commit

Permalink
Handle Get Address Info when Address does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret committed Mar 26, 2024
1 parent d08421a commit 32e9534
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ArtemisNetCoreClient/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ActiveMQ.Artemis.Core.Client;
public interface ISession : IAsyncDisposable
{
Task CreateAddress(string address, IEnumerable<RoutingType> routingTypes, CancellationToken cancellationToken);
Task<AddressInfo> GetAddressInfo(string address, CancellationToken cancellationToken);
Task<AddressInfo?> GetAddressInfo(string address, CancellationToken cancellationToken);
Task CreateQueue(QueueConfiguration queueConfiguration, CancellationToken cancellationToken);
Task<QueueInfo> GetQueueInfo(string queueName, CancellationToken cancellationToken);
}
19 changes: 12 additions & 7 deletions src/ArtemisNetCoreClient/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,25 @@ public async Task CreateAddress(string address, IEnumerable<RoutingType> routing
_ = await SendBlockingAsync<CreateAddressMessage, NullResponse>(createAddressMessage, cancellationToken);
}

public async Task<AddressInfo> GetAddressInfo(string address, CancellationToken cancellationToken)
public async Task<AddressInfo?> GetAddressInfo(string address, CancellationToken cancellationToken)
{
var request = new SessionBindingQueryMessage
{
Address = address
};
var response = await SendBlockingAsync<SessionBindingQueryMessage, SessionBindingQueryResponseMessageV5>(request, cancellationToken);
return new AddressInfo

if (response.Exists)
{
Name = address,
QueueNames = response.QueueNames,
RoutingTypes = GetRoutingTypes(response).ToArray(),
};
return new AddressInfo
{
Name = address,
QueueNames = response.QueueNames,
RoutingTypes = GetRoutingTypes(response).ToArray(),
};
}

return null;
}

private static IEnumerable<RoutingType> GetRoutingTypes(SessionBindingQueryResponseMessageV5 sessionBindingQueryResponseMessageV5)
Expand Down
21 changes: 21 additions & 0 deletions test/ArtemisNetCoreClient.Tests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,25 @@ await session.CreateQueue(new QueueConfiguration
Assert.That(queueInfo.AddressName, Is.EqualTo(addressName));
Assert.That(queueInfo.RoutingType, Is.EqualTo(routingType));
}

[Test]
public async Task should_not_return_address_info_when_address_does_not_exist()
{
// Arrange
var connectionFactory = new SessionFactory();
await using var session = await connectionFactory.CreateAsync(new Endpoint
{
Host = "localhost",
Port = 5445,
User = "artemis",
Password = "artemis"
});

// Act
var addressName = Guid.NewGuid().ToString();
var addressInfo = await session.GetAddressInfo(addressName, default);

// Assert
Assert.That(addressInfo, Is.Null);
}
}

0 comments on commit 32e9534

Please sign in to comment.