Skip to content

Commit 6f68bd8

Browse files
authored
Merge pull request #140 from TraGicCode/chore/add-routing-topology-and-queue-type-for-rabbit-transport
Add Routing Topology and QueueType to RabbitMQ Transport
2 parents 73c19c6 + 38400d9 commit 6f68bd8

File tree

5 files changed

+85
-12
lines changed

5 files changed

+85
-12
lines changed

src/BuslyCLI.Console/Config/RabbitmqTransportConfig.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@
22

33
public class RabbitmqTransportConfig : ITransportConfig
44
{
5+
// TODO: Add Support for TLS Client Certificate Authentication
6+
// https://github.com/Particular/NServiceBus.RabbitMQ/blob/master/src/NServiceBus.Transport.RabbitMQ/Connection/ConnectionFactory.cs#L69
57
// TODO: Test TLS Connections to broker using "amqps://your-username:[email protected]:5671/vhost"
68
public string AmqpConnectionString { get; set; }
79

8-
// TODO: Add Support for TLS Client Certificate Authentication
9-
// https://github.com/Particular/NServiceBus.RabbitMQ/blob/master/src/NServiceBus.Transport.RabbitMQ/Connection/ConnectionFactory.cs#L69
10+
public RabbitmqRoutingTopology RoutingTopology { get; set; } = RabbitmqRoutingTopology.Conventional;
11+
public RabbitmqQueueType QueueType { get; set; } = RabbitmqQueueType.Quorum;
1012

1113
public ManagementApi ManagementApi { get; set; }
1214
}
1315

16+
public enum RabbitmqRoutingTopology
17+
{
18+
Conventional,
19+
Direct,
20+
}
21+
22+
public enum RabbitmqQueueType
23+
{
24+
Quorum,
25+
Classic,
26+
}
27+
1428
public class ManagementApi
1529
{
1630
public string Url { get; set; }

src/BuslyCLI.Console/Config/Validators/RabbitMQTransportConfigValidator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public RabbitMQTransportConfigValidator()
99
RuleFor(x => x.AmqpConnectionString)
1010
.NotEmpty();
1111

12+
RuleFor(x => x.RoutingTopology)
13+
.IsInEnum();
14+
1215
RuleFor(x => x.ManagementApi)
1316
.SetValidator(new ManagementApiConfigValidator());
1417
}

src/BuslyCLI.Console/Factories/RawEndpointFactory.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ private TransportDefinition CreateSqlServerTransport(SqlServerTransportConfig sq
6969

7070
private RabbitMQTransport CreateRabbitMQTransport(RabbitmqTransportConfig rabbitmqTransportConfig)
7171
{
72-
var t = new RabbitMQTransport(RoutingTopology.Conventional(QueueType.Quorum), rabbitmqTransportConfig.AmqpConnectionString);
72+
var routingTopology = rabbitmqTransportConfig.RoutingTopology switch
73+
{
74+
RabbitmqRoutingTopology.Conventional => RoutingTopology.Conventional(rabbitmqTransportConfig.QueueType == RabbitmqQueueType.Quorum ? QueueType.Quorum : QueueType.Classic),
75+
RabbitmqRoutingTopology.Direct => RoutingTopology.Direct(rabbitmqTransportConfig.QueueType == RabbitmqQueueType.Quorum ? QueueType.Quorum : QueueType.Classic),
76+
_ => throw new Exception("Unknown RabbitMQ routing topology: " + rabbitmqTransportConfig.RoutingTopology)
77+
};
78+
var t = new RabbitMQTransport(routingTopology, rabbitmqTransportConfig.AmqpConnectionString);
7379

7480
if (rabbitmqTransportConfig.ManagementApi != null)
7581
{
76-
t.ManagementApiConfiguration =
77-
CreateManagementApiConfig(rabbitmqTransportConfig.ManagementApi);
82+
t.ManagementApiConfiguration = CreateManagementApiConfig(rabbitmqTransportConfig.ManagementApi);
7883
}
7984
return t;
8085
}

src/BuslyCLI.Console/Spectre/AppConfiguration.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using BuslyCLI.Commands.Demo;
44
using BuslyCLI.Commands.Event;
55
using BuslyCLI.Commands.Transport;
6+
using Spectre.Console;
67
using Spectre.Console.Cli;
8+
using YamlDotNet.Core;
79

810
namespace BuslyCLI.Spectre;
911

@@ -53,9 +55,24 @@ public static Action<IConfigurator> GetSpectreCommandConfiguration()
5355
demo.AddCommand<StartDemoCommand>("start")
5456
.WithDescription("Start a demo endpoint that can receive any command and a single 'Messages.Events.OrderPlaced' event.");
5557
});
56-
#if DEBUG
57-
config.PropagateExceptions();
58-
#endif
58+
59+
config.SetExceptionHandler((ex, _) =>
60+
{
61+
// if (ex.InnerException is OptionsValidationException)
62+
// {
63+
// AnsiConsole.Write(new Markup($"{ConsoleExtensions.ErrorMarkup}{ex.InnerException.Message}"));
64+
// return;
65+
// }
66+
// if (ex is CommandAppException)
67+
// {
68+
// AnsiConsole.Write(new Markup($"{ConsoleExtensions.ErrorMarkup}{ex.Message}"));
69+
// return;
70+
// }
71+
// AnsiConsole.WriteException(ex, ExceptionFormats.ShortenPaths);
72+
AnsiConsole.WriteException(ex, ExceptionFormats.ShortenEverything);
73+
});
74+
75+
5976
};
6077
}
6178
}

website/docs/transports/rabbitmq.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ transports:
2222
2323
## `rabbitmq-transport-config` Fields
2424

25-
| Field | Required | Type | Default | Description |
26-
| ------------------------ | -------- | ------ | ------- | ----------------------------------------------------------------- |
27-
| `amqp-connection-string` | **Yes** | string | — | Full AMQP connection string used to connect to RabbitMQ. |
28-
| `management-api` | No | object | — | Optional configuration to connect to the RabbitMQ Management API. |
25+
| Field | Required | Type | Default | Description |
26+
| ------------------------ | -------- | ------ | ------------ | ----------------------------------------------------------------- |
27+
| `amqp-connection-string` | **Yes** | string | — | Full AMQP connection string used to connect to RabbitMQ. |
28+
| `routing-toplogy` | No | string | conventional | Routing toplogy to be used (Conventional or Direct). |
29+
| `queue-type` | No | string | quorum | Type of queues RabbitMQ is using (Quorum or Classic). |
30+
| `management-api` | No | object | — | Optional configuration to connect to the RabbitMQ Management API. |
2931

3032
---
3133

@@ -57,6 +59,38 @@ amqp-connection-string: amqps://user:[email protected]:5671/my-vhost
5759

5860
---
5961

62+
### `routing-topology` (optional)
63+
64+
The Routing topology to be used for the transport
65+
66+
Examples:
67+
68+
```yaml
69+
routing-toplogy: conventional
70+
```
71+
72+
```yaml
73+
routing-toplogy: direct
74+
```
75+
76+
---
77+
78+
### `queue-type` (optional)
79+
80+
The type of queues being used.
81+
82+
Examples:
83+
84+
```yaml
85+
queue-type: quorum
86+
```
87+
88+
```yaml
89+
queue-type: classic
90+
```
91+
92+
---
93+
6094
### `management-api` (optional)
6195

6296
Allows Busly to interact with the RabbitMQ Management API for monitoring or queue management.

0 commit comments

Comments
 (0)