-
Notifications
You must be signed in to change notification settings - Fork 2
RabbitMQ direct exchange implemented #33
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
Draft
matteopessina
wants to merge
1
commit into
main
Choose a base branch
from
9-queue-crud-rabbitmq
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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
18 changes: 16 additions & 2 deletions
18
src/Server/EventBusExplorer.Server.Infrastructure.RabbitMQ/DataTransferObjects.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 |
|---|---|---|
| @@ -1,9 +1,23 @@ | ||
| using System.Runtime.Serialization; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace EventBusExplorer.Server.Infrastructure.RabbitMQ; | ||
|
|
||
| internal record ExchangeTopic( | ||
| internal record Exchange( | ||
| string Name, | ||
| bool Durable, | ||
| [property: JsonPropertyName("auto_delete")] bool AutoDelete, | ||
| string Type = "topic"); | ||
| ExchangeType Type); | ||
|
|
||
| [JsonConverter(typeof(JsonStringEnumMemberConverter))] | ||
| internal enum ExchangeType | ||
| { | ||
| [EnumMember(Value = "topic")] | ||
| Topic, | ||
| [EnumMember(Value = "direct")] | ||
| Direct, | ||
| [EnumMember(Value = "fanout")] | ||
| Fanout, | ||
| [EnumMember(Value = "headers")] | ||
| Headers | ||
| } |
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
56 changes: 56 additions & 0 deletions
56
src/Server/EventBusExplorer.Server.Infrastructure.RabbitMQ/RabbitMQQueuesService.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,56 @@ | ||
| using EventBusExplorer.Server.Application.ServiceBroker.Abstractions; | ||
|
|
||
| namespace EventBusExplorer.Server.Infrastructure.RabbitMQ; | ||
|
|
||
| public class RabbitMQQueuesService : IServiceBrokerQueuesService | ||
| { | ||
| private readonly RabbitMQAdministrationClient _adminClient; | ||
|
|
||
| public RabbitMQQueuesService( | ||
| RabbitMQAdministrationClient adminClient | ||
| ) | ||
| { | ||
| _adminClient = adminClient; | ||
| } | ||
|
|
||
| public async Task<string> CreateAsync(string? name, CancellationToken cancellationToken = default) | ||
| { | ||
| await _adminClient.CreateExchangeAsync( | ||
| name, | ||
| type: ExchangeType.Direct, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| // | ||
| // Since exchange creation through management API does not return anything, | ||
| // It is assumed that if the request is successful then the exchange has been created. | ||
| // | ||
| return name!; | ||
| } | ||
|
|
||
| public async Task DeleteAsync(string name, CancellationToken cancellationToken = default) | ||
| { | ||
| await _adminClient.DeleteExchangeAsync(name, cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| public async Task<IList<string>> GetAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| IList<Exchange> directExchanges = await _adminClient.GetExchangesAsync( | ||
| type: ExchangeType.Direct, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| return directExchanges.Select(x => x.Name).ToList(); | ||
| } | ||
|
|
||
| public async Task<string> GetAsync(string name, CancellationToken cancellationToken = default) | ||
| { | ||
| Exchange? directExchange = await _adminClient.GetExchangeAsync( | ||
| name, | ||
| type: ExchangeType.Direct, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| if (directExchange is null) | ||
| throw new Exception($"Cannot find exchange with name: {name}"); //TODO: define or find a suitable exc type | ||
|
|
||
| return directExchange.Name; | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -15,8 +15,9 @@ RabbitMQAdministrationClient adminClient | |
|
|
||
| public async Task<string> CreateTopicAsync(string? name, CancellationToken cancellationToken = default) | ||
| { | ||
| await _adminClient.CreateTopicAsync( | ||
| await _adminClient.CreateExchangeAsync( | ||
| name, | ||
| type: ExchangeType.Topic, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| // | ||
|
|
@@ -28,24 +29,29 @@ await _adminClient.CreateTopicAsync( | |
|
|
||
| public async Task<IList<string>> GetTopicsAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| IList<ExchangeTopic> topics = await _adminClient.GetTopicsAsync( | ||
| IList<Exchange> topicExchanges = await _adminClient.GetExchangesAsync( | ||
| type: ExchangeType.Topic, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| return topics.Select(x => x.Name).ToList(); | ||
| return topicExchanges.Select(x => x.Name).ToList(); | ||
| } | ||
|
|
||
| public async Task<string> GetTopicAsync(string name, CancellationToken cancellationToken = default) | ||
| { | ||
| ExchangeTopic topic = await _adminClient.GetTopicAsync( | ||
| Exchange? topic = await _adminClient.GetExchangeAsync( | ||
| name, | ||
| type: ExchangeType.Topic, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| if (topic is null) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Krusty93 probably in this case we want to return at API level something like 204 or 404. |
||
| throw new Exception($"Cannot find exchange with name: {name}"); //TODO: define or find a suitable exc type | ||
|
|
||
| return topic.Name; | ||
| } | ||
|
|
||
| public async Task DeleteTopicAsync(string name, CancellationToken cancellationToken = default) | ||
| { | ||
| await _adminClient.DeleteTopicAsync(name, cancellationToken: cancellationToken); | ||
| await _adminClient.DeleteExchangeAsync(name, cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| public Task<IList<string>> GetSubscriptionsAsync(string topicName, CancellationToken cancellationToken = default) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/floweSB/event-bus-explorer/pull/33/files#r1260310492