Skip to content

Commit 975aa6d

Browse files
committed
[Host.RabbitMq] Convert ExchangeType from enum to a string. Add x-delayed-message type.
Signed-off-by: Tomasz Maruszak <[email protected]>
1 parent 545105a commit 975aa6d

13 files changed

+83
-118
lines changed

src/Host.Plugin.Properties.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Import Project="Common.NuGet.Properties.xml" />
55

66
<PropertyGroup>
7-
<Version>3.2.0-rc101</Version>
7+
<Version>3.2.0-rc102</Version>
88
</PropertyGroup>
99

1010
</Project>

src/SlimMessageBus.Host.Configuration/SlimMessageBus.Host.Configuration.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Description>Core configuration interfaces of SlimMessageBus</Description>
77
<PackageTags>SlimMessageBus</PackageTags>
88
<RootNamespace>SlimMessageBus.Host</RootNamespace>
9-
<Version>3.2.0-rc101</Version>
9+
<Version>3.2.0-rc102</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
namespace SlimMessageBus.Host.RabbitMQ;
22

3-
public enum ExchangeType
3+
public static class ExchangeType
44
{
55
/// <summary>
66
/// Exchange type used for AMQP direct exchanges.
77
/// </summary>
8-
Direct = 0,
8+
public static readonly string Direct = global::RabbitMQ.Client.ExchangeType.Direct;
99

1010
/// <summary>
1111
/// Exchange type used for AMQP fanout exchanges.
1212
/// </summary>
13-
Fanout = 1,
13+
public static readonly string Fanout = global::RabbitMQ.Client.ExchangeType.Fanout;
1414

1515
/// <summary>
1616
/// Exchange type used for AMQP headers exchanges.
1717
/// </summary>
18-
Headers = 2,
18+
public static readonly string Headers = global::RabbitMQ.Client.ExchangeType.Headers;
1919

2020
/// <summary>
2121
/// Exchange type used for AMQP topic exchanges.
2222
/// </summary>
23-
Topic = 3
23+
public static readonly string Topic = global::RabbitMQ.Client.ExchangeType.Topic;
24+
25+
/// <summary>
26+
/// Exchange type used for Delayed Message Plugin exchanges.
27+
/// See more: <see href="https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq#installing-the-plugin"/>
28+
/// </summary>
29+
public static readonly string XDelayedMessage = "x-delayed-message";
2430
}

src/SlimMessageBus.Host.RabbitMQ/Config/RabbitMqConsumerBuilderExtensions.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ public static TConsumerBuilder Queue<TConsumerBuilder>(this TConsumerBuilder bui
1818
{
1919
if (string.IsNullOrEmpty(queueName)) throw new ArgumentNullException(nameof(queueName));
2020

21-
builder.ConsumerSettings.Properties[RabbitMqProperties.QueueName] = queueName;
21+
RabbitMqProperties.QueueName.Set(builder.ConsumerSettings, queueName);
2222

2323
if (exclusive != null)
2424
{
25-
builder.ConsumerSettings.Properties[RabbitMqProperties.QueueExclusive] = exclusive.Value;
25+
RabbitMqProperties.QueueExclusive.Set(builder.ConsumerSettings, exclusive.Value);
2626
}
2727

2828
if (durable != null)
2929
{
30-
builder.ConsumerSettings.Properties[RabbitMqProperties.QueueDurable] = durable.Value;
30+
RabbitMqProperties.QueueDurable.Set(builder.ConsumerSettings, durable.Value);
3131
}
3232

3333
if (autoDelete != null)
3434
{
35-
builder.ConsumerSettings.Properties[RabbitMqProperties.QueueAutoDelete] = autoDelete.Value;
35+
RabbitMqProperties.QueueAutoDelete.Set(builder.ConsumerSettings, autoDelete.Value);
3636
}
3737

3838
if (arguments != null)
3939
{
40-
builder.ConsumerSettings.Properties[RabbitMqProperties.QueueArguments] = arguments;
40+
RabbitMqProperties.QueueArguments.Set(builder.ConsumerSettings, arguments);
4141
}
4242

4343
return builder;
@@ -58,7 +58,7 @@ public static TConsumerBuilder ExchangeBinding<TConsumerBuilder>(this TConsumerB
5858
if (string.IsNullOrEmpty(exchangeName)) throw new ArgumentNullException(nameof(exchangeName));
5959

6060
builder.ConsumerSettings.Path = exchangeName;
61-
builder.ConsumerSettings.Properties[RabbitMqProperties.BindingRoutingKey] = routingKey;
61+
RabbitMqProperties.BindingRoutingKey.Set(builder.ConsumerSettings, routingKey);
6262

6363
return builder;
6464
}
@@ -70,36 +70,36 @@ public static TConsumerBuilder ExchangeBinding<TConsumerBuilder>(this TConsumerB
7070
/// <typeparam name="TConsumerBuilder"></typeparam>
7171
/// <param name="builder"></param>
7272
/// <param name="exchangeName">Will set the "x-dead-letter-exchange" argument on the queue</param>
73-
/// <param name="exchangeType">Type of the exchange, when provided SMB will attempt to provision the exchange</param>
73+
/// <param name="exchangeType">Type of the exchange, when provided SMB will attempt to provision the exchange. See <see cref="ExchangeType"/>.</param>
7474
/// <param name="durable"></param>
7575
/// <param name="autoDelete"></param>
7676
/// <param name="routingKey">Will set the "x-dead-letter-routing-key" argument on the queue</param>
7777
/// <returns></returns>
78-
public static TConsumerBuilder DeadLetterExchange<TConsumerBuilder>(this TConsumerBuilder builder, string exchangeName, ExchangeType? exchangeType = null, bool? durable = null, bool? autoDelete = null, string routingKey = null)
78+
public static TConsumerBuilder DeadLetterExchange<TConsumerBuilder>(this TConsumerBuilder builder, string exchangeName, string exchangeType = null, bool? durable = null, bool? autoDelete = null, string routingKey = null)
7979
where TConsumerBuilder : AbstractConsumerBuilder
8080
{
8181
if (string.IsNullOrEmpty(exchangeName)) throw new ArgumentNullException(nameof(exchangeName));
8282

83-
builder.ConsumerSettings.Properties[RabbitMqProperties.DeadLetterExchange] = exchangeName;
83+
RabbitMqProperties.DeadLetterExchange.Set(builder.ConsumerSettings, exchangeName);
8484

8585
if (exchangeType != null)
8686
{
87-
builder.ConsumerSettings.Properties[RabbitMqProperties.DeadLetterExchangeType] = RabbitMqProducerBuilderExtensions.MapExchangeType(exchangeType.Value);
87+
RabbitMqProperties.DeadLetterExchangeType.Set(builder.ConsumerSettings, exchangeType);
8888
}
8989

9090
if (durable != null)
9191
{
92-
builder.ConsumerSettings.Properties[RabbitMqProperties.DeadLetterExchangeDurable] = durable.Value;
92+
RabbitMqProperties.DeadLetterExchangeDurable.Set(builder.ConsumerSettings, durable.Value);
9393
}
9494

9595
if (autoDelete != null)
9696
{
97-
builder.ConsumerSettings.Properties[RabbitMqProperties.DeadLetterExchangeAutoDelete] = autoDelete.Value;
97+
RabbitMqProperties.DeadLetterExchangeAutoDelete.Set(builder.ConsumerSettings, autoDelete.Value);
9898
}
9999

100100
if (routingKey != null)
101101
{
102-
builder.ConsumerSettings.Properties[RabbitMqProperties.DeadLetterExchangeRoutingKey] = routingKey;
102+
RabbitMqProperties.DeadLetterExchangeRoutingKey.Set(builder.ConsumerSettings, routingKey);
103103
}
104104

105105
return builder;
@@ -115,7 +115,7 @@ public static TConsumerBuilder DeadLetterExchange<TConsumerBuilder>(this TConsum
115115
public static TConsumerBuilder AcknowledgementMode<TConsumerBuilder>(this TConsumerBuilder builder, RabbitMqMessageAcknowledgementMode mode)
116116
where TConsumerBuilder : AbstractConsumerBuilder
117117
{
118-
builder.ConsumerSettings.Properties[RabbitMqProperties.MessageAcknowledgementMode] = mode;
118+
RabbitMqProperties.MessageAcknowledgementMode.Set(builder.ConsumerSettings, mode);
119119
return builder;
120120
}
121121
}

src/SlimMessageBus.Host.RabbitMQ/Config/RabbitMqConsumerContextExtensions.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@ public static class RabbitMqConsumerContextExtensions
88

99
public static BasicDeliverEventArgs GetTransportMessage(this IConsumerContext context)
1010
{
11-
#if NETSTANDARD2_0
1211
if (context is null) throw new ArgumentNullException(nameof(context));
13-
#else
14-
ArgumentNullException.ThrowIfNull(context);
15-
#endif
1612

17-
return context.GetPropertyOrDefault<BasicDeliverEventArgs>(RabbitMqProperties.Message);
13+
return context.GetPropertyOrDefault<BasicDeliverEventArgs>(RabbitMqProperties.Message.Key);
1814
}
1915

2016
static internal void SetTransportMessage(this IConsumerContext context, BasicDeliverEventArgs message)
2117
{
22-
#if NETSTANDARD2_0
2318
if (context is null) throw new ArgumentNullException(nameof(context));
24-
#else
25-
ArgumentNullException.ThrowIfNull(context);
26-
#endif
2719

28-
context.Properties[RabbitMqProperties.Message] = message;
20+
context.Properties[RabbitMqProperties.Message.Key] = message;
2921
}
3022

3123
static internal void SetConfirmAction(this IConsumerContext consumerContext, RabbitMqMessageConfirmAction messageConfirmAction)

src/SlimMessageBus.Host.RabbitMQ/Config/RabbitMqMessageBusSettingsExtensions.cs

+14-37
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ public static class RabbitMqMessageBusSettingsExtensions
99
/// <param name="action">Action to be executed, the first param is the RabbitMQ <see cref="IModel"/> from the underlying client, and second parameter represents the SMB exchange, queue and binding setup</param>
1010
public static RabbitMqMessageBusSettings UseTopologyInitializer(this RabbitMqMessageBusSettings settings, RabbitMqTopologyInitializer action)
1111
{
12-
#if NETSTANDARD2_0
1312
if (settings is null) throw new ArgumentNullException(nameof(settings));
1413
if (action is null) throw new ArgumentNullException(nameof(action));
15-
#else
16-
ArgumentNullException.ThrowIfNull(settings);
17-
ArgumentNullException.ThrowIfNull(action);
18-
#endif
1914

20-
settings.Properties[RabbitMqProperties.TopologyInitializer] = action;
15+
RabbitMqProperties.TopologyInitializer.Set(settings, action);
2116
return settings;
2217
}
2318

@@ -32,11 +27,11 @@ public static RabbitMqMessageBusSettings UseExchangeDefaults(this RabbitMqMessag
3227
{
3328
if (durable != null)
3429
{
35-
settings.Properties[RabbitMqProperties.ExchangeDurable] = durable.Value;
30+
RabbitMqProperties.ExchangeDurable.Set(settings, durable.Value);
3631
}
3732
if (autoDelete != null)
3833
{
39-
settings.Properties[RabbitMqProperties.ExchangeAutoDelete] = autoDelete.Value;
34+
RabbitMqProperties.ExchangeAutoDelete.Set(settings, autoDelete.Value);
4035
}
4136
return settings;
4237
}
@@ -45,28 +40,28 @@ public static RabbitMqMessageBusSettings UseExchangeDefaults(this RabbitMqMessag
4540
/// Sets the default settings for dead letter exchanges on the bus level. This default will be taken unless it is overridden at the relevant producer level.
4641
/// </summary>
4742
/// <param name="settings"></param>
48-
/// <param name="exchangeType"></param>
43+
/// <param name="exchangeType">See <see cref="ExchangeType"/></param>
4944
/// <param name="durable"></param>
5045
/// <param name="autoDelete"></param>
5146
/// <param name="routingKey"></param>
5247
/// <returns></returns>
53-
public static RabbitMqMessageBusSettings UseDeadLetterExchangeDefaults(this RabbitMqMessageBusSettings settings, ExchangeType? exchangeType = null, bool? durable = null, bool? autoDelete = null, string routingKey = null)
48+
public static RabbitMqMessageBusSettings UseDeadLetterExchangeDefaults(this RabbitMqMessageBusSettings settings, string exchangeType = null, bool? durable = null, bool? autoDelete = null, string routingKey = null)
5449
{
5550
if (exchangeType != null)
5651
{
57-
settings.Properties[RabbitMqProperties.DeadLetterExchangeType] = RabbitMqProducerBuilderExtensions.MapExchangeType(exchangeType.Value);
52+
RabbitMqProperties.DeadLetterExchangeType.Set(settings, exchangeType);
5853
}
5954
if (durable != null)
6055
{
61-
settings.Properties[RabbitMqProperties.DeadLetterExchangeDurable] = durable.Value;
56+
RabbitMqProperties.DeadLetterExchangeDurable.Set(settings, durable.Value);
6257
}
6358
if (autoDelete != null)
6459
{
65-
settings.Properties[RabbitMqProperties.DeadLetterExchangeAutoDelete] = autoDelete.Value;
60+
RabbitMqProperties.DeadLetterExchangeAutoDelete.Set(settings, autoDelete.Value);
6661
}
6762
if (routingKey != null)
6863
{
69-
settings.Properties[RabbitMqProperties.DeadLetterExchangeRoutingKey] = routingKey;
64+
RabbitMqProperties.DeadLetterExchangeRoutingKey.Set(settings, routingKey);
7065
}
7166
return settings;
7267
}
@@ -80,19 +75,15 @@ public static RabbitMqMessageBusSettings UseDeadLetterExchangeDefaults(this Rabb
8075
/// <returns></returns>
8176
public static RabbitMqMessageBusSettings UseQueueDefaults(this RabbitMqMessageBusSettings settings, bool? durable = null, bool? autoDelete = null)
8277
{
83-
#if NETSTANDARD2_0
8478
if (settings is null) throw new ArgumentNullException(nameof(settings));
85-
#else
86-
ArgumentNullException.ThrowIfNull(settings);
87-
#endif
8879

8980
if (durable != null)
9081
{
91-
settings.Properties[RabbitMqProperties.QueueDurable] = durable.Value;
82+
RabbitMqProperties.QueueDurable.Set(settings, durable.Value);
9283
}
9384
if (autoDelete != null)
9485
{
95-
settings.Properties[RabbitMqProperties.QueueAutoDelete] = autoDelete.Value;
86+
RabbitMqProperties.QueueAutoDelete.Set(settings, autoDelete.Value);
9687
}
9788
return settings;
9889
}
@@ -105,15 +96,10 @@ public static RabbitMqMessageBusSettings UseQueueDefaults(this RabbitMqMessageBu
10596
/// <returns></returns>
10697
public static RabbitMqMessageBusSettings UseMessagePropertiesModifier(this RabbitMqMessageBusSettings settings, RabbitMqMessagePropertiesModifier<object> messagePropertiesModifier)
10798
{
108-
#if NETSTANDARD2_0
10999
if (settings is null) throw new ArgumentNullException(nameof(settings));
110100
if (messagePropertiesModifier is null) throw new ArgumentNullException(nameof(messagePropertiesModifier));
111-
#else
112-
ArgumentNullException.ThrowIfNull(settings);
113-
ArgumentNullException.ThrowIfNull(messagePropertiesModifier);
114-
#endif
115101

116-
settings.Properties[RabbitMqProperties.MessagePropertiesModifier] = messagePropertiesModifier;
102+
RabbitMqProperties.MessagePropertiesModifier.Set(settings, messagePropertiesModifier);
117103
return settings;
118104
}
119105

@@ -125,15 +111,10 @@ public static RabbitMqMessageBusSettings UseMessagePropertiesModifier(this Rabbi
125111
/// <returns></returns>
126112
public static RabbitMqMessageBusSettings UseRoutingKeyProvider(this RabbitMqMessageBusSettings settings, RabbitMqMessageRoutingKeyProvider<object> routingKeyProvider)
127113
{
128-
#if NETSTANDARD2_0
129114
if (settings is null) throw new ArgumentNullException(nameof(settings));
130115
if (routingKeyProvider is null) throw new ArgumentNullException(nameof(routingKeyProvider));
131-
#else
132-
ArgumentNullException.ThrowIfNull(settings);
133-
ArgumentNullException.ThrowIfNull(routingKeyProvider);
134-
#endif
135116

136-
settings.Properties[RabbitMqProperties.MessageRoutingKeyProvider] = routingKeyProvider;
117+
RabbitMqProperties.MessageRoutingKeyProvider.Set(settings, routingKeyProvider);
137118
return settings;
138119
}
139120

@@ -145,13 +126,9 @@ public static RabbitMqMessageBusSettings UseRoutingKeyProvider(this RabbitMqMess
145126
/// <returns></returns>
146127
public static RabbitMqMessageBusSettings AcknowledgementMode(this RabbitMqMessageBusSettings settings, RabbitMqMessageAcknowledgementMode mode)
147128
{
148-
#if NETSTANDARD2_0
149129
if (settings is null) throw new ArgumentNullException(nameof(settings));
150-
#else
151-
ArgumentNullException.ThrowIfNull(settings);
152-
#endif
153130

154-
settings.Properties[RabbitMqProperties.MessageAcknowledgementMode] = mode;
131+
RabbitMqProperties.MessageAcknowledgementMode.Set(settings, mode);
155132
return settings;
156133
}
157134
}

0 commit comments

Comments
 (0)