public void TestImmediateAckingTracker() { var builder = new ConsumerConfigBuilder <byte[]>(); builder.AcknowledgmentGroupTime(0); builder.Topic($"TestAckTracker-{Guid.NewGuid()}"); builder.SubscriptionName($"TestAckTracker-sub-{Guid.NewGuid()}"); var conf = builder.ConsumerConfigurationData; var consumer = _client.NewConsumer(builder); var unack = _system.ActorOf(UnAckedChunckedMessageIdSequenceMap.Prop()); var tracker = _client.ActorSystem.ActorOf(PersistentAcknowledgmentsGroupingTracker <byte[]> .Prop(unack, consumer.ConsumerActor, consumer.ConsumerActor /*dummy*/, 1, consumer.ConsumerActor, conf)); var msg1 = new MessageId(5, 1, 0); var msg2 = new MessageId(5, 2, 0); var isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(new AddAcknowledgment(msg1, CommandAck.AckType.Individual, new Dictionary <string, long>())); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(FlushPending.Instance); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(new AddAcknowledgment(msg2, CommandAck.AckType.Individual, new Dictionary <string, long>())); // Since we were connected, the ack went out immediately isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.GracefulStop(TimeSpan.FromSeconds(1)); }
public void TestUnAckMessageRedeliveryWithReceive() { var topic = $"persistent://public/default/async-unack-redelivery-{Guid.NewGuid()}"; var builder = new ConsumerConfigBuilder <byte[]>(); builder.Topic(topic); builder.SubscriptionName("sub-TestUnAckMessageRedeliveryWithReceive"); builder.AckTimeout(TimeSpan.FromMilliseconds(8000)); builder.ForceTopicCreation(true); builder.AcknowledgmentGroupTime(0); builder.SubscriptionType(Protocol.Proto.CommandSubscribe.SubType.Shared); var consumer = _client.NewConsumer(builder); var pBuilder = new ProducerConfigBuilder <byte[]>(); pBuilder.Topic(topic); var producer = _client.NewProducer(pBuilder); const int messageCount = 10; for (var i = 0; i < messageCount; i++) { var receipt = producer.Send(Encoding.UTF8.GetBytes("my-message-" + i)); _output.WriteLine(JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true })); } var messageReceived = 0; Thread.Sleep(TimeSpan.FromSeconds(5)); for (var i = 0; i < messageCount; ++i) { var m = consumer.Receive(); var receivedMessage = Encoding.UTF8.GetString(m.Data); _output.WriteLine($"Received message: [{receivedMessage}]"); Assert.NotNull(receivedMessage); messageReceived++; } Assert.Equal(10, messageReceived); Thread.Sleep(TimeSpan.FromSeconds(10)); for (var i = 0; i < messageCount; i++) { var m = consumer.Receive(); var receivedMessage = Encoding.UTF8.GetString(m.Data); _output.WriteLine($"Received message: [{receivedMessage}]"); Assert.NotNull(receivedMessage); messageReceived++; } Assert.Equal(20, messageReceived); producer.Close(); consumer.Close(); }
public void TestAckTracker() { var builder = new ConsumerConfigBuilder <byte[]>(); builder.AcknowledgmentGroupTime(10000); builder.Topic($"TestAckTracker-{Guid.NewGuid()}"); builder.SubscriptionName($"TestAckTracker-sub-{Guid.NewGuid()}"); var conf = builder.ConsumerConfigurationData; var consumer = _client.NewConsumer(builder); var unack = _system.ActorOf(UnAckedChunckedMessageIdSequenceMap.Prop()); var tracker = _client.ActorSystem.ActorOf(PersistentAcknowledgmentsGroupingTracker <byte[]> .Prop(unack, consumer.ConsumerActor, consumer.ConsumerActor /*dummy*/, 1, consumer.ConsumerActor, conf)); var msg1 = new MessageId(5, 1, 0); var msg2 = new MessageId(5, 2, 0); var msg3 = new MessageId(5, 3, 0); var msg4 = new MessageId(5, 4, 0); var msg5 = new MessageId(5, 5, 0); var msg6 = new MessageId(5, 6, 0); var isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(new AddAcknowledgment(msg1, CommandAck.AckType.Individual, new Dictionary <string, long>())); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(new AddAcknowledgment(msg5, CommandAck.AckType.Cumulative, new Dictionary <string, long>())); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult(); Assert.False(isDuplicate); // Flush while disconnected. the internal tracking will not change tracker.Tell(FlushPending.Instance); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.Tell(new AddAcknowledgment(msg6, CommandAck.AckType.Individual, new Dictionary <string, long>())); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult(); Assert.True(isDuplicate); tracker.Tell(FlushPending.Instance); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult(); Assert.True(isDuplicate); isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult(); Assert.False(isDuplicate); tracker.GracefulStop(TimeSpan.FromSeconds(1)); }