Skip to content

Commit

Permalink
Support for FirstAcquirer field
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret committed Aug 18, 2021
1 parent acaf000 commit 993f87d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ActiveMQ.Artemis.Client/Message/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public uint? Ttl
}

public uint DeliveryCount => _innerHeader.HasField(4) ? _innerHeader.DeliveryCount : default;

public bool FirstAcquirer => _innerHeader.FirstAcquirer;
}
}
6 changes: 6 additions & 0 deletions src/ActiveMQ.Artemis.Client/Message/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public byte[] UserId
/// </summary>
public uint DeliveryCount => Header.DeliveryCount;

/// <summary>
/// If this value is true, then this message has not been acquired by any other link.
/// If this value is false, then this message MAY have previously been acquired by another link or links.
/// </summary>
public bool FirstAcquirer => Header.FirstAcquirer;

public DurabilityMode? DurabilityMode
{
get => Header.Durable switch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace ActiveMQ.Artemis.Client.IntegrationTests
{
public class MessageFirstAcquirerSpec : ActiveMQNetIntegrationSpec
{
public MessageFirstAcquirerSpec(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task Should_receive_msg_with_FirstAcquirer_set_when_msg_was_received_for_the_first_time()
{
await using var connection = await CreateConnection();
var address = Guid.NewGuid().ToString();
await using var producer = await connection.CreateProducerAsync(address, RoutingType.Anycast);
await using var consumer1 = await connection.CreateConsumerAsync(address, RoutingType.Anycast);
await using var consumer2 = await connection.CreateConsumerAsync(address, RoutingType.Anycast);

await producer.SendAsync(new Message("foo"));
var msg = await consumer1.ReceiveAsync(CancellationToken);
Assert.True(msg.FirstAcquirer);
}

[Fact]
public async Task Should_receive_msg_with_FirstAcquirer_set_to_false_when_msg_was_redelivered()
{
await using var connection = await CreateConnection();
var address = Guid.NewGuid().ToString();
await using var producer = await connection.CreateProducerAsync(address, RoutingType.Anycast);
await using var consumer1 = await connection.CreateConsumerAsync(address, RoutingType.Anycast);
await using var consumer2 = await connection.CreateConsumerAsync(address, RoutingType.Anycast);

await producer.SendAsync(new Message("foo"));
var msg = await consumer1.ReceiveAsync(CancellationToken);
consumer1.Reject(msg);

var msg2 = await consumer2.ReceiveAsync(CancellationToken);
Assert.False(msg2.FirstAcquirer);
}
}
}

0 comments on commit 993f87d

Please sign in to comment.