diff --git a/src/Paramore.Brighter/CommandProcessor.cs b/src/Paramore.Brighter/CommandProcessor.cs index 1fa10586e1..7949791bb4 100644 --- a/src/Paramore.Brighter/CommandProcessor.cs +++ b/src/Paramore.Brighter/CommandProcessor.cs @@ -542,12 +542,12 @@ public Guid DepositPost(T request) where T : class, IRequest /// database, that you want to signal via the request to downstream consumers /// Pass deposited Guid to /// - /// The requests to save to the outbox + /// The requests to save to the outbox /// The type of the request /// The Id of the Message that has been deposited. - public Guid[] DepositPost(IEnumerable request) where T : class, IRequest + public Guid[] DepositPost(IEnumerable requests) where T : class, IRequest { - return DepositPost(request, _boxTransactionConnectionProvider); + return DepositPost(requests, _boxTransactionConnectionProvider); } private Guid DepositPost(T request, IAmABoxTransactionConnectionProvider connectionProvider) where T : class, IRequest diff --git a/src/Paramore.Brighter/IAmACommandProcessor.cs b/src/Paramore.Brighter/IAmACommandProcessor.cs index d316ded53d..911914385e 100644 --- a/src/Paramore.Brighter/IAmACommandProcessor.cs +++ b/src/Paramore.Brighter/IAmACommandProcessor.cs @@ -102,6 +102,18 @@ public interface IAmACommandProcessor /// Guid DepositPost(T request) where T : class, IRequest; + /// + /// Adds a messages into the outbox, and returns the id of the saved message. + /// Intended for use with the Outbox pattern: http://gistlabs.com/2014/05/the-outbox/ normally you include the + /// call to DepositPostBox within the scope of the transaction to write corresponding entity state to your + /// database, that you want to signal via the request to downstream consumers + /// Pass deposited Guid to + /// + /// The requests to save to the outbox + /// The type of the request + /// The Id of the Message that has been deposited. + public Guid[] DepositPost(IEnumerable requests) where T : class, IRequest; + /// /// Adds a message into the outbox, and returns the id of the saved message. /// Intended for use with the Outbox pattern: http://gistlabs.com/2014/05/the-outbox/ normally you include the @@ -114,6 +126,21 @@ public interface IAmACommandProcessor /// Task DepositPostAsync(T request, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest; + /// + /// Adds a message into the outbox, and returns the id of the saved message. + /// Intended for use with the Outbox pattern: http://gistlabs.com/2014/05/the-outbox/ normally you include the + /// call to DepositPostBox within the scope of the transaction to write corresponding entity state to your + /// database, that you want to signal via the request to downstream consumers + /// Pass deposited Guid to + /// + /// The requests to save to the outbox + /// Should we use the calling thread's synchronization context when continuing or a default thread synchronization context. Defaults to false + /// The Cancellation Token. + /// The type of the request + /// + Task DepositPostAsync(IEnumerable requests, bool continueOnCapturedContext = false, + CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest; + /// /// Flushes the message box message given by to the broker. /// Intended for use with the Outbox pattern: http://gistlabs.com/2014/05/the-outbox/ diff --git a/tests/Paramore.Brighter.Core.Tests/MessageDispatch/TestDoubles/SpyCommandProcessor.cs b/tests/Paramore.Brighter.Core.Tests/MessageDispatch/TestDoubles/SpyCommandProcessor.cs index 63e77e42a9..dc19aaba95 100644 --- a/tests/Paramore.Brighter.Core.Tests/MessageDispatch/TestDoubles/SpyCommandProcessor.cs +++ b/tests/Paramore.Brighter.Core.Tests/MessageDispatch/TestDoubles/SpyCommandProcessor.cs @@ -46,7 +46,7 @@ enum CommandType Call } - internal class SpyCommandProcessor : IAmACommandProcessor + internal class SpyCommandProcessor : Paramore.Brighter.IAmACommandProcessor { private readonly Queue _requests = new Queue(); private readonly Dictionary _postBox = new Dictionary(); @@ -113,6 +113,17 @@ public Guid DepositPost(T request) where T : class, IRequest return request.Id; } + public Guid[] DepositPost(IEnumerable request) where T : class, IRequest + { + var ids = new List(); + foreach (T r in request) + { + ids.Add(DepositPost(r)); + } + + return ids.ToArray(); + } + public async Task DepositPostAsync(T request, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest { @@ -123,6 +134,18 @@ public async Task DepositPostAsync(T request, bool continueOnCapturedCo return await tcs.Task; } + public async Task DepositPostAsync(IEnumerable requests, bool continueOnCapturedContext = false, + CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest + { + var ids = new List(); + foreach (T r in requests) + { + ids.Add(await DepositPostAsync(r, cancellationToken: cancellationToken)); + } + + return ids.ToArray(); + } + public void ClearOutbox(params Guid[] posts) { foreach (var messageId in posts) diff --git a/tests/Paramore.Brighter.InMemory.Tests/TestDoubles/FakeCommandProcessor.cs b/tests/Paramore.Brighter.InMemory.Tests/TestDoubles/FakeCommandProcessor.cs index 955184ba15..38c42c218a 100644 --- a/tests/Paramore.Brighter.InMemory.Tests/TestDoubles/FakeCommandProcessor.cs +++ b/tests/Paramore.Brighter.InMemory.Tests/TestDoubles/FakeCommandProcessor.cs @@ -78,6 +78,17 @@ public Guid DepositPost(T request) where T : class, IRequest return request.Id; } + public Guid[] DepositPost(IEnumerable request) where T : class, IRequest + { + var ids = new List(); + foreach (T r in request) + { + ids.Add(DepositPost(r)); + } + + return ids.ToArray(); + } + public Task DepositPostAsync(T request, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -93,6 +104,18 @@ public Guid DepositPost(T request) where T : class, IRequest } + public async Task DepositPostAsync(IEnumerable requests, bool continueOnCapturedContext = false, + CancellationToken cancellationToken = default(CancellationToken)) where T : class, IRequest + { + var ids = new List(); + foreach (T r in requests) + { + ids.Add(await DepositPostAsync(r, cancellationToken: cancellationToken)); + } + + return ids.ToArray(); + } + public void ClearOutbox(params Guid[] posts) { foreach (var post in posts)