-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1995 from preardon/issue/failureToImplicitClear
Fix Threading issue on Implicit Clear
- Loading branch information
Showing
30 changed files
with
485 additions
and
125 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 |
---|---|---|
@@ -1,43 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Paramore.Brighter | ||
namespace Paramore.Brighter | ||
{ | ||
public class OutboxSweeper | ||
{ | ||
private readonly int _milliSecondsSinceSent; | ||
private readonly int _millisecondsSinceSent; | ||
private readonly IAmACommandProcessor _commandProcessor; | ||
private readonly int _batchSize; | ||
private readonly bool _useBulk; | ||
|
||
/// <summary> | ||
/// This sweeper clears an outbox of any outstanding messages within the time interval | ||
/// </summary> | ||
/// <param name="milliSecondsSinceSent">How long can a message sit in the box before we attempt to resend</param> | ||
/// <param name="millisecondsSinceSent">How long can a message sit in the box before we attempt to resend</param> | ||
/// <param name="commandProcessor">Who should post the messages</param> | ||
/// <param name="batchSize">The maximum number of messages to dispatch.</param> | ||
/// <param name="useBulk">Use the producers bulk dispatch functionality.</param> | ||
public OutboxSweeper(int milliSecondsSinceSent, IAmACommandProcessor commandProcessor, int batchSize = 100, | ||
public OutboxSweeper(int millisecondsSinceSent, IAmACommandProcessor commandProcessor, int batchSize = 100, | ||
bool useBulk = false) | ||
{ | ||
_milliSecondsSinceSent = milliSecondsSinceSent; | ||
_millisecondsSinceSent = millisecondsSinceSent; | ||
_commandProcessor = commandProcessor; | ||
_batchSize = batchSize; | ||
_useBulk = useBulk; | ||
} | ||
|
||
/// <summary> | ||
/// Dispatches the oldest un-dispatched messages from the outbox in a background thread. | ||
/// </summary> | ||
public void Sweep() | ||
{ | ||
_commandProcessor.ClearOutbox(_batchSize, _milliSecondsSinceSent); | ||
_commandProcessor.ClearOutbox(_batchSize, _millisecondsSinceSent); | ||
} | ||
|
||
public Task SweepAsync(CancellationToken cancellationToken = default) | ||
/// <summary> | ||
/// Dispatches the oldest un-dispatched messages from the asynchronous outbox in a background thread. | ||
/// </summary> | ||
public void SweepAsyncOutbox() | ||
{ | ||
_commandProcessor.ClearAsyncOutbox(_batchSize, _milliSecondsSinceSent, _useBulk); | ||
|
||
return Task.CompletedTask; | ||
_commandProcessor.ClearAsyncOutbox(_batchSize, _millisecondsSinceSent, _useBulk); | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...er.Core.Tests/CommandProcessors/TestDoubles/FakeMessageProducerWithPublishConfirmation.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,40 @@ | ||
#region Licence | ||
/* The MIT License (MIT) | ||
Copyright © 2015 Toby Henderson <hendersont@gmail.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
|
||
#endregion | ||
|
||
using System; | ||
|
||
namespace Paramore.Brighter.Core.Tests.CommandProcessors.TestDoubles | ||
{ | ||
public class FakeMessageProducerWithPublishConfirmation : FakeMessageProducer, ISupportPublishConfirmation | ||
{ | ||
public event Action<bool, Guid> OnMessagePublished; | ||
|
||
public new void Send(Message message) | ||
{ | ||
MessageWasSent = true; | ||
SentMessages.Add(message); | ||
OnMessagePublished?.Invoke(true, message.Id); | ||
} | ||
} | ||
} |
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.