-
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.
Operations: added send and topic mode (#4)
* Operations: added send and topic mode It is now possible to configure workflow engine to use send mode instead of publish for events. Topic based sending support was also added. * added message header enrichment
- Loading branch information
Showing
30 changed files
with
538 additions
and
179 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
src/Rebus.Operations/Rebus.Operations.Abstractions/IOperationDispatcher.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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dbosoft.Rebus.Operations | ||
{ | ||
public interface IOperationDispatcher | ||
{ | ||
ValueTask<IOperation?> StartNew<T>(object? additionalData = default) where T : class, new(); | ||
ValueTask<IOperation?> StartNew(Type commandType, object? additionalData = default); | ||
ValueTask<IOperation?> StartNew(object operationCommand); | ||
ValueTask<IOperation?> StartNew<T>(object? additionalData = default, IDictionary<string,string>? additionalHeaders = null) where T : class, new(); | ||
ValueTask<IOperation?> StartNew(Type commandType, object? additionalData = default, IDictionary<string,string>? additionalHeaders = null); | ||
ValueTask<IOperation?> StartNew(object operationCommand, IDictionary<string,string>? additionalHeaders = null); | ||
|
||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
src/Rebus.Operations/Rebus.Operations.Abstractions/IOperationTaskDispatcher.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
21 changes: 21 additions & 0 deletions
21
src/Rebus.Operations/Rebus.Operations.Abstractions/ITaskMessaging.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,21 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dbosoft.Rebus.Operations; | ||
|
||
public interface ITaskMessaging | ||
{ | ||
Task FailTask(IOperationTaskMessage message, string errorMessage, | ||
IDictionary<string, string>? additionalHeaders = null); | ||
|
||
Task FailTask(IOperationTaskMessage message, ErrorData error, | ||
IDictionary<string, string>? additionalHeaders = null); | ||
|
||
Task CompleteTask(IOperationTaskMessage message, IDictionary<string, string>? additionalHeaders = null); | ||
|
||
Task CompleteTask(IOperationTaskMessage message, object responseMessage, | ||
IDictionary<string, string>? additionalHeaders = null); | ||
|
||
Task ProgressMessage(IOperationTaskMessage message, object data, | ||
IDictionary<string, string>? additionalHeaders = null); | ||
} |
18 changes: 16 additions & 2 deletions
18
src/Rebus.Operations/Rebus.Operations.Abstractions/Workflow/IMessageEnricher.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 |
---|---|---|
@@ -1,8 +1,22 @@ | ||
using Dbosoft.Rebus.Operations.Commands; | ||
using System.Collections.Generic; | ||
using Dbosoft.Rebus.Operations.Commands; | ||
using Dbosoft.Rebus.Operations.Events; | ||
|
||
namespace Dbosoft.Rebus.Operations.Workflow; | ||
|
||
public interface IMessageEnricher | ||
{ | ||
object? EnrichTaskAcceptedReply<T>(OperationTaskSystemMessage<T> taskMessage) where T : class, new(); | ||
} | ||
|
||
IDictionary<string, string>? EnrichHeadersFromIncomingSystemMessage<T>(OperationTaskSystemMessage<T> taskMessage, | ||
IDictionary<string, string> systemMessageHeaders); | ||
|
||
IDictionary<string, string>? EnrichHeadersOfOutgoingSystemMessage(object taskMessage, | ||
IDictionary<string, string>? previousHeaders); | ||
|
||
IDictionary<string, string>? EnrichHeadersOfStatusEvent(OperationStatusEvent operationStatusEvent, | ||
IDictionary<string, string>? previousHeaders); | ||
|
||
IDictionary<string, string>? EnrichHeadersOfTaskStatusEvent(OperationTaskStatusEvent operationStatusEvent, | ||
IDictionary<string, string>? previousHeaders); | ||
} |
13 changes: 6 additions & 7 deletions
13
src/Rebus.Operations/Rebus.Operations.Abstractions/Workflow/IOperationMessaging.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Dbosoft.Rebus.Operations.Events; | ||
|
||
namespace Dbosoft.Rebus.Operations.Workflow; | ||
|
||
public interface IOperationMessaging | ||
{ | ||
Task DispatchTaskMessage(object command, IOperationTask task); | ||
Task DispatchTaskStatusEventAsync(string commandType, OperationTaskStatusEvent message); | ||
Task DispatchTaskStatusEventAsync(OperationTaskStatusEvent message); | ||
Task DispatchOperationStatusEventAsync(OperationStatusEvent operationStatusEvent); | ||
Task DispatchTaskMessage(object command, IOperationTask task, IDictionary<string,string>? additionalHeaders = null); | ||
Task DispatchTaskStatusEventAsync(string commandType, OperationTaskStatusEvent message, IDictionary<string,string>? additionalHeaders = null); | ||
Task DispatchTaskStatusEventAsync(OperationTaskStatusEvent message, IDictionary<string,string>? additionalHeaders = null); | ||
Task DispatchOperationStatusEventAsync(OperationStatusEvent operationStatusEvent, IDictionary<string,string>? additionalHeaders = null); | ||
|
||
IOperationDispatcher OperationDispatcher { get; } | ||
IOperationTaskDispatcher TaskDispatcher { get; } | ||
|
||
|
||
} |
65 changes: 20 additions & 45 deletions
65
src/Rebus.Operations/Rebus.Operations.Core/BusOperationTaskExtensions.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 |
---|---|---|
@@ -1,57 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Dbosoft.Rebus.Operations.Events; | ||
using Dbosoft.Rebus.Operations.Workflow; | ||
using Rebus.Bus; | ||
using Rebus.Transport; | ||
|
||
namespace Dbosoft.Rebus.Operations; | ||
|
||
public static class BusOperationTaskExtensions | ||
{ | ||
public static Task FailTask(this IBus bus, IOperationTaskMessage message, string errorMessage) | ||
public static Task SendWorkflowEvent(this IBus bus, WorkflowOptions options, object eventMessage, | ||
IDictionary<string, string>? additionalHeaders = null) | ||
{ | ||
return FailTask(bus, message, new ErrorData { ErrorMessage = errorMessage }); | ||
} | ||
|
||
public static Task FailTask(this IBus bus, IOperationTaskMessage message, ErrorData error) | ||
{ | ||
return bus.Publish( | ||
OperationTaskStatusEvent.Failed( | ||
message.OperationId, message.InitiatingTaskId, | ||
message.TaskId, error)); | ||
} | ||
|
||
|
||
public static Task CompleteTask(this IBus bus, IOperationTaskMessage message) | ||
{ | ||
return bus.Publish( | ||
OperationTaskStatusEvent.Completed( | ||
message.OperationId, message.InitiatingTaskId, message.TaskId)); | ||
} | ||
|
||
public static Task CompleteTask(this IBus bus, IOperationTaskMessage message, object responseMessage) | ||
{ | ||
return bus.Publish( | ||
OperationTaskStatusEvent.Completed( | ||
message.OperationId, message.InitiatingTaskId, message.TaskId, responseMessage)); | ||
} | ||
|
||
|
||
public static async Task ProgressMessage(this IBus bus, IOperationTaskMessage message, object data) | ||
{ | ||
using var scope = new RebusTransactionScope(); | ||
|
||
|
||
await bus.Publish(new OperationTaskProgressEvent | ||
if (string.IsNullOrWhiteSpace(options.EventDestination)) | ||
{ | ||
Id = Guid.NewGuid(), | ||
OperationId = message.OperationId, | ||
TaskId = message.TaskId, | ||
Data = data, | ||
Timestamp = DateTimeOffset.UtcNow | ||
}).ConfigureAwait(false); | ||
|
||
// commit it like this | ||
await scope.CompleteAsync().ConfigureAwait(false); | ||
return options.DispatchMode switch | ||
{ | ||
WorkflowEventDispatchMode.Publish => bus.Publish(eventMessage, additionalHeaders), | ||
WorkflowEventDispatchMode.Send => bus.Send(eventMessage, additionalHeaders), | ||
_ => throw new ArgumentOutOfRangeException(nameof(options)) | ||
}; | ||
} | ||
|
||
return options.DispatchMode switch | ||
{ | ||
WorkflowEventDispatchMode.Publish => bus.Advanced.Topics.Publish(options.EventDestination, eventMessage, additionalHeaders), | ||
WorkflowEventDispatchMode.Send => bus.Advanced.Routing.Send(options.EventDestination, eventMessage, additionalHeaders), | ||
_ => throw new ArgumentOutOfRangeException(nameof(options)) | ||
}; | ||
} | ||
|
||
} |
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
12 changes: 11 additions & 1 deletion
12
src/Rebus.Operations/Rebus.Operations.Core/OperationsSetup.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
Oops, something went wrong.