-
-
Notifications
You must be signed in to change notification settings - Fork 803
Adds RabbitMQ Bus Level Configuration #9328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bffeb5
Adds `ConfigureDefaults` to rabbitmq
PascalSenn f21c87c
cleanup
PascalSenn 1563ceb
cleanup
PascalSenn 41ef1dd
Merge branch 'main' into pse/adds-rabbitmq-defaults-to-mocha
PascalSenn 043bab4
Merge branch 'main' into pse/adds-rabbitmq-defaults-to-mocha
PascalSenn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/Mocha/src/Mocha.Transport.RabbitMQ/Configurations/RabbitMQBusDefaults.cs
This file contains hidden or 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,20 @@ | ||
| namespace Mocha.Transport.RabbitMQ; | ||
|
|
||
| /// <summary> | ||
| /// Defines bus-level defaults that are applied to all auto-provisioned queues and exchanges | ||
| /// when they are created by topology conventions. | ||
| /// </summary> | ||
| public sealed class RabbitMQBusDefaults | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the default queue configuration that is applied to all auto-provisioned queues. | ||
| /// Individual queue settings will override these defaults. | ||
| /// </summary> | ||
| public RabbitMQDefaultQueueOptions Queue { get; set; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the default exchange configuration that is applied to all auto-provisioned exchanges. | ||
| /// Individual exchange settings will override these defaults. | ||
| /// </summary> | ||
| public RabbitMQDefaultExchangeOptions Exchange { get; set; } = new(); | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/Mocha/src/Mocha.Transport.RabbitMQ/Configurations/RabbitMQDefaultExchangeOptions.cs
This file contains hidden or 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,50 @@ | ||
| namespace Mocha.Transport.RabbitMQ; | ||
|
|
||
| /// <summary> | ||
| /// Default options for exchanges created by topology conventions. | ||
| /// </summary> | ||
| public sealed class RabbitMQDefaultExchangeOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the default exchange type. | ||
| /// When set, all auto-provisioned exchanges will use this type unless explicitly overridden. | ||
| /// </summary> | ||
| public string? Type { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets whether exchanges are durable by default. | ||
| /// Default is null (uses the RabbitMQ default of true). | ||
| /// </summary> | ||
| public bool? Durable { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets whether exchanges are auto-deleted by default. | ||
| /// Default is null (uses the RabbitMQ default of false). | ||
| /// </summary> | ||
| public bool? AutoDelete { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets additional default arguments applied to all auto-provisioned exchanges. | ||
| /// </summary> | ||
| public Dictionary<string, object> Arguments { get; set; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// Applies these defaults to an exchange configuration, without overriding explicitly set values. | ||
| /// </summary> | ||
| internal void ApplyTo(RabbitMQExchangeConfiguration configuration) | ||
| { | ||
| configuration.Type ??= Type; | ||
| configuration.Durable ??= Durable; | ||
| configuration.AutoDelete ??= AutoDelete; | ||
|
|
||
| if (Arguments.Count > 0) | ||
| { | ||
| configuration.Arguments ??= new Dictionary<string, object>(); | ||
|
|
||
| foreach (var (key, value) in Arguments) | ||
| { | ||
| configuration.Arguments.TryAdd(key, value); | ||
| } | ||
| } | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/Mocha/src/Mocha.Transport.RabbitMQ/Configurations/RabbitMQDefaultQueueOptions.cs
This file contains hidden or 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,69 @@ | ||
| namespace Mocha.Transport.RabbitMQ; | ||
|
|
||
| /// <summary> | ||
| /// Default options for queues created by topology conventions. | ||
| /// </summary> | ||
| public sealed class RabbitMQDefaultQueueOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the default queue type (Classic, Quorum, or Stream). | ||
| /// When set, all auto-provisioned queues will use this queue type unless explicitly overridden. | ||
| /// </summary> | ||
| public string? QueueType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets whether queues are durable by default. | ||
| /// Default is null (uses the RabbitMQ default of true). | ||
| /// </summary> | ||
| public bool? Durable { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets whether queues are auto-deleted by default. | ||
| /// Default is null (uses the RabbitMQ default of false). | ||
| /// </summary> | ||
| public bool? AutoDelete { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets additional default arguments applied to all auto-provisioned queues. | ||
| /// </summary> | ||
| public Dictionary<string, object> Arguments { get; set; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// Applies these defaults to a queue configuration, without overriding explicitly set values. | ||
| /// Quorum and stream queue types are not applied to queues that have auto-delete or exclusive | ||
| /// set, since those properties are incompatible with these queue types. Default arguments are | ||
| /// also skipped for incompatible queues because they may contain queue-type-specific settings | ||
| /// (e.g. <c>x-delivery-limit</c> is only valid for quorum queues). | ||
| /// </summary> | ||
| internal void ApplyTo(RabbitMQQueueConfiguration configuration) | ||
| { | ||
| configuration.Durable ??= Durable; | ||
| configuration.AutoDelete ??= AutoDelete; | ||
|
|
||
| // Quorum and stream queues do not support auto-delete or exclusive properties. | ||
| // Skip applying queue type and default arguments for incompatible configurations | ||
| // (e.g. reply queues) since default arguments are often queue-type-specific. | ||
| var isIncompatibleWithQueueType = | ||
| configuration.AutoDelete is true || configuration.Exclusive is true; | ||
|
|
||
| if (isIncompatibleWithQueueType) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (Arguments.Count > 0 || QueueType is not null) | ||
| { | ||
| configuration.Arguments ??= new Dictionary<string, object>(); | ||
|
|
||
| if (QueueType is not null) | ||
| { | ||
| configuration.Arguments.TryAdd("x-queue-type", QueueType); | ||
| } | ||
|
|
||
| foreach (var (key, value) in Arguments) | ||
| { | ||
| configuration.Arguments.TryAdd(key, value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.