-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FluentWorkflow.RabbitMQ引入IRabbitMQExchangeSelector,以能够动态的改变消息发送…
…时使用的交换机
- Loading branch information
1 parent
6c3e9e4
commit 6abd883
Showing
10 changed files
with
157 additions
and
51 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
42 changes: 42 additions & 0 deletions
42
src/FluentWorkflow.RabbitMQ.Legacy/IRabbitMQExchangeSelector.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,42 @@ | ||
using System.ComponentModel; | ||
using FluentWorkflow.Interface; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FluentWorkflow.RabbitMQ; | ||
|
||
/// <summary> | ||
/// RabbitMQ交换机选择器 | ||
/// </summary> | ||
public interface IRabbitMQExchangeSelector | ||
{ | ||
#region Public 方法 | ||
|
||
/// <summary> | ||
/// 获取消息 <paramref name="message"/> 应该使用的交换机 | ||
/// </summary> | ||
/// <typeparam name="TMessage"></typeparam> | ||
/// <param name="message"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
string GetExchange<TMessage>(TMessage message, CancellationToken cancellationToken = default) where TMessage : class, IWorkflowMessage, IWorkflowContextCarrier<IWorkflowContext>, IEventNameDeclaration; | ||
|
||
#endregion Public 方法 | ||
} | ||
|
||
/// <summary> | ||
/// 基于 <see cref="RabbitMQOptions"/> 的交换机选择器 | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Advanced)] | ||
public sealed class OptionsBasedRabbitMQExchangeSelector(IOptionsMonitor<RabbitMQOptions> optionsMonitor) : IRabbitMQExchangeSelector | ||
{ | ||
#region Public 方法 | ||
|
||
/// <inheritdoc/> | ||
public string GetExchange<TMessage>(TMessage message, CancellationToken cancellationToken) | ||
where TMessage : class, IWorkflowMessage, IWorkflowContextCarrier<IWorkflowContext>, IEventNameDeclaration | ||
{ | ||
return optionsMonitor.CurrentValue.ExchangeName ?? RabbitMQOptions.DefaultExchangeName; | ||
} | ||
|
||
#endregion Public 方法 | ||
} |
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,42 @@ | ||
using System.ComponentModel; | ||
using FluentWorkflow.Interface; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FluentWorkflow.RabbitMQ; | ||
|
||
/// <summary> | ||
/// RabbitMQ交换机选择器 | ||
/// </summary> | ||
public interface IRabbitMQExchangeSelector | ||
{ | ||
#region Public 方法 | ||
|
||
/// <summary> | ||
/// 获取消息 <paramref name="message"/> 应该使用的交换机 | ||
/// </summary> | ||
/// <typeparam name="TMessage"></typeparam> | ||
/// <param name="message"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
ValueTask<string> GetExchangeAsync<TMessage>(TMessage message, CancellationToken cancellationToken = default) where TMessage : class, IWorkflowMessage, IWorkflowContextCarrier<IWorkflowContext>, IEventNameDeclaration; | ||
|
||
#endregion Public 方法 | ||
} | ||
|
||
/// <summary> | ||
/// 基于 <see cref="RabbitMQOptions"/> 的交换机选择器 | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Advanced)] | ||
public sealed class OptionsBasedRabbitMQExchangeSelector(IOptionsMonitor<RabbitMQOptions> optionsMonitor) : IRabbitMQExchangeSelector | ||
{ | ||
#region Public 方法 | ||
|
||
/// <inheritdoc/> | ||
public ValueTask<string> GetExchangeAsync<TMessage>(TMessage message, CancellationToken cancellationToken) | ||
where TMessage : class, IWorkflowMessage, IWorkflowContextCarrier<IWorkflowContext>, IEventNameDeclaration | ||
{ | ||
return ValueTask.FromResult(optionsMonitor.CurrentValue.ExchangeName ?? RabbitMQOptions.DefaultExchangeName); | ||
} | ||
|
||
#endregion Public 方法 | ||
} |
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