forked from apache/pulsar-dotpulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: apache#46 support nack delay and ack timeouts
* feat: apache#45 `Consumer` now supports `NegativeAcknowledge` * add `AcknowledgementTimeout` to `ConsumerOptions` * add `NegativeAcknowledgementRedeliveryDelay` to `ConsumerOptions` * add `NegativeackedMessageState` to manage nacked messages * add `UnackedMessageState` to manage unacked messages * add `MessageTracker` to periodically check unacked and nacked messages, on a fixed polling timeout of 10ms * add `AwaitingAck` to track both unacked and nacked messages * add `InactiveMessageTracker` to reduce overhead when no `AcknowledgementTimeout` or `NegativeAcknowledgementRedeliveryDelay` is configured * add `InactiveNegativeackedMessageState` to reduce overhead when no `NegativeAcknowledgementRedeliveryDelay` is configured * add `InactiveUnackedMessageState` to reduce overhead when no `AcknowledgementTimeout` is configured * update `ConsumerBuilder` to allow setting `AcknowledgementTimeout` * update `ConsumerBuilder` to allow setting `NegativeAcknowledgementRedeliveryDelay` * refactor `ConsumerChannel` to support `NegativeAcknowledge` * refactor `AsyncQueue<T>` to implement missing interface `IAsyncQueue<T>` * refactor `BatchHandler<TMessage>` to implement missing interface `IBatchHandler<TMessage>` * add `AutoFixture` and `AutoFixture.AutoNSubstitute` dependencies to unit test project * add missing `ConsumerBuilderTests` unit tests * add missing `ConsumerChannelFactoryTests` unit tests * add missing `ConsumerChannelTests` unit tests * add missing `ConsumerTests` unit tests * add IntegrationTests for consumer ack timout and nack delays * skipped integration test `SinglePartition_WhenSendMessages_ThenGetMessagesFromSinglePartition` to avoid CI failures * skipped integration test `RoundRobinPartition_WhenSendMessages_ThenGetMessagesFromPartitionsInOrder` to avoid CI failures Closes: apache#46 Closes: apache#45
- Loading branch information
1 parent
8580679
commit e7df3a5
Showing
38 changed files
with
2,200 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using System; | ||
|
||
public interface IAsyncQueue<T> : IEnqueue<T>, IDequeue<T>, IDisposable | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using DotPulsar.Abstractions; | ||
using PulsarApi; | ||
using System.Buffers; | ||
|
||
public interface IBatchHandler<TMessage> | ||
{ | ||
IMessage<TMessage> Add(MessageIdData messageId, uint redeliveryCount, MessageMetadata metadata, ReadOnlySequence<byte> data); | ||
IMessage<TMessage>? GetNext(); | ||
void Clear(); | ||
MessageIdData? Acknowledge(MessageIdData messageId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using DotPulsar.Internal.PulsarApi; | ||
using System; | ||
|
||
public interface IMessageQueue : IDequeue<MessagePackage>, IDisposable | ||
{ | ||
void Acknowledge(MessageIdData messageId); | ||
|
||
void NegativeAcknowledge(MessageIdData messageId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using DotPulsar.Abstractions; | ||
using PulsarApi; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public interface IMessageTracker : IDisposable | ||
{ | ||
Task Start(IConsumer consumer, CancellationToken cancellationToken = default); | ||
|
||
void Track(MessageIdData messageId); | ||
|
||
void Acknowledge(MessageIdData messageId); | ||
|
||
void NegativeAcknowledge(MessageIdData messageId); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/DotPulsar/Internal/Abstractions/INegativeackedMessageState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using DotPulsar.Internal.PulsarApi; | ||
using System.Collections.Generic; | ||
|
||
public interface INegativeackedMessageState | ||
{ | ||
void Add(MessageIdData messageId); | ||
|
||
IEnumerable<MessageIdData> GetMessagesForRedelivery(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/DotPulsar/Internal/Abstractions/IUnackedMessageState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal.Abstractions | ||
{ | ||
using DotPulsar.Internal.PulsarApi; | ||
using System.Collections.Generic; | ||
|
||
public interface IUnackedMessageState | ||
{ | ||
void Add(MessageIdData messageId); | ||
|
||
void Remove(MessageIdData messageId); | ||
|
||
void Acknowledge(MessageIdData messageId); | ||
|
||
IEnumerable<MessageIdData> CheckUnackedMessages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace DotPulsar.Internal | ||
{ | ||
using PulsarApi; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
public readonly struct AwaitingAck | ||
{ | ||
public MessageIdData MessageId { get; } | ||
public long Timestamp { get; } | ||
|
||
public AwaitingAck(MessageIdData messageId) | ||
{ | ||
MessageId = messageId; | ||
Timestamp = Stopwatch.GetTimestamp(); | ||
} | ||
|
||
public TimeSpan Elapsed => TimeSpan.FromTicks( | ||
(long) ((Stopwatch.GetTimestamp() - Timestamp) / (double) Stopwatch.Frequency * TimeSpan.TicksPerSecond)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.