Skip to content

Commit c2cbd1f

Browse files
committed
[Host.Configuration] Backward compatibility with 2.x
Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
1 parent e20f496 commit c2cbd1f

File tree

9 files changed

+49
-19
lines changed

9 files changed

+49
-19
lines changed

src/Host.Plugin.Properties.xml

Lines changed: 1 addition & 1 deletion
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.0.0-rc6</Version>
7+
<Version>3.0.0-rc11</Version>
88
</PropertyGroup>
99

1010
</Project>

src/SlimMessageBus.Host.Configuration/Builders/ConsumerBuilder.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ public ConsumerBuilder(MessageBusSettings settings, Type messageType = null)
88
ConsumerSettings.ConsumerMode = ConsumerMode.Consumer;
99
}
1010

11-
public ConsumerBuilder<TMessage> Path(string path, Action<ConsumerBuilder<TMessage>> pathConfig = null)
11+
public ConsumerBuilder<TMessage> Path(string path)
1212
{
1313
ConsumerSettings.Path = path;
14+
return this;
15+
}
16+
17+
public ConsumerBuilder<TMessage> Path(string path, Action<ConsumerBuilder<TMessage>> pathConfig)
18+
{
19+
Path(path);
1420
pathConfig?.Invoke(this);
1521
return this;
1622
}
1723

18-
public ConsumerBuilder<TMessage> Topic(string topic, Action<ConsumerBuilder<TMessage>> topicConfig = null) => Path(topic, topicConfig);
24+
public ConsumerBuilder<TMessage> Topic(string topic)
25+
=> Path(topic);
26+
27+
public ConsumerBuilder<TMessage> Topic(string topic, Action<ConsumerBuilder<TMessage>> topicConfig)
28+
=> Path(topic, topicConfig);
1929

2030
private static Task DefaultConsumerOnMethod<T>(object consumer, object message, IConsumerContext consumerContext, CancellationToken cancellationToken)
2131
=> ((IConsumer<T>)consumer).OnHandle((T)message, cancellationToken);

src/SlimMessageBus.Host.Configuration/Builders/HandlerBuilder.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,53 @@ protected AbstractHandlerBuilder(MessageBusSettings settings, Type messageType,
1414
}
1515

1616
protected THandlerBuilder TypedThis => (THandlerBuilder)this;
17+
18+
/// <summary>
19+
/// Configure topic name (or queue name) that incoming requests (<see cref="TRequest"/>) are expected on.
20+
/// </summary>
21+
/// <param name="path">Topic name</param>
22+
/// <returns></returns>
23+
public THandlerBuilder Path(string path)
24+
{
25+
var consumerSettingsExist = Settings.Consumers.Any(x => x.Path == path && x.ConsumerMode == ConsumerMode.RequestResponse && x != ConsumerSettings);
26+
if (consumerSettingsExist)
27+
{
28+
throw new ConfigurationMessageBusException($"Attempted to configure request handler for path '{path}' when one was already configured. There can only be one request handler for a given path.");
29+
}
30+
31+
ConsumerSettings.Path = path;
32+
return TypedThis;
33+
}
1734

1835
/// <summary>
1936
/// Configure topic name (or queue name) that incoming requests (<see cref="TRequest"/>) are expected on.
2037
/// </summary>
2138
/// <param name="path">Topic name</param>
2239
/// <param name="pathConfig"></param>
2340
/// <returns></returns>
24-
public THandlerBuilder Path(string path, Action<THandlerBuilder> pathConfig = null)
25-
{
26-
var consumerSettingsExist = Settings.Consumers.Any(x => x.Path == path && x.ConsumerMode == ConsumerMode.RequestResponse && x != ConsumerSettings);
27-
if (consumerSettingsExist)
28-
{
29-
throw new ConfigurationMessageBusException($"Attempted to configure request handler for path '{path}' when one was already configured. There can only be one request handler for a given path (topic/queue)");
30-
}
31-
32-
ConsumerSettings.Path = path;
41+
public THandlerBuilder Path(string path, Action<THandlerBuilder> pathConfig)
42+
{
43+
Path(path);
3344
pathConfig?.Invoke(TypedThis);
3445
return TypedThis;
3546
}
3647

48+
/// <summary>
49+
/// Configure topic name (or queue name) that incoming requests (<see cref="TRequest"/>) are expected on.
50+
/// </summary>
51+
/// <param name="topic">Topic name</param>
52+
/// <returns></returns>
53+
public THandlerBuilder Topic(string topic)
54+
=> Path(topic);
55+
3756
/// <summary>
3857
/// Configure topic name (or queue name) that incoming requests (<see cref="TRequest"/>) are expected on.
3958
/// </summary>
4059
/// <param name="topic">Topic name</param>
4160
/// <param name="topicConfig"></param>
4261
/// <returns></returns>
43-
public THandlerBuilder Topic(string topic, Action<THandlerBuilder> topicConfig = null) => Path(topic, topicConfig);
62+
public THandlerBuilder Topic(string topic, Action<THandlerBuilder> topicConfig)
63+
=> Path(topic, topicConfig);
4464

4565
public THandlerBuilder Instances(int numberOfInstances)
4666
{

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

Lines changed: 1 addition & 1 deletion
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.0.0-rc6</Version>
9+
<Version>3.0.0-rc11</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>

src/SlimMessageBus.Host.Interceptor/SlimMessageBus.Host.Interceptor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="../Common.NuGet.Properties.xml" />
44

55
<PropertyGroup>
6-
<Version>3.0.0-rc6</Version>
6+
<Version>3.0.0-rc11</Version>
77
<Description>Core interceptor interfaces of SlimMessageBus</Description>
88
<PackageTags>SlimMessageBus</PackageTags>
99
</PropertyGroup>

src/SlimMessageBus.Host.Serialization/SlimMessageBus.Host.Serialization.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="../Common.NuGet.Properties.xml" />
44

55
<PropertyGroup>
6-
<Version>3.0.0-rc6</Version>
6+
<Version>3.0.0-rc11</Version>
77
<Description>Core serialization interfaces of SlimMessageBus</Description>
88
<PackageTags>SlimMessageBus</PackageTags>
99
</PropertyGroup>

src/SlimMessageBus/SlimMessageBus.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="../Common.NuGet.Properties.xml" />
44

55
<PropertyGroup>
6-
<Version>3.0.0-rc6</Version>
6+
<Version>3.0.0-rc11</Version>
77
<Description>
88
This library provides a lightweight, easy-to-use message bus interface for .NET, offering a simplified facade for working with messaging brokers.
99
It supports multiple transport providers for popular messaging systems, as well as in-memory (in-process) messaging for efficient local communication.

src/Tests/SlimMessageBus.Host.Configuration.Test/HandlerBuilderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void When_PathSet_Given_ThePathWasUsedBeforeOnAnotherHandler_Then_Excepti
7070
// assert
7171
act.Should()
7272
.Throw<ConfigurationMessageBusException>()
73-
.WithMessage($"Attempted to configure request handler for path '*' when one was already configured. There can only be one request handler for a given path (topic/queue)");
73+
.WithMessage($"Attempted to configure request handler for path '*' when one was already configured. There can only be one request handler for a given path.");
7474
}
7575

7676
[Theory]

src/Tests/SlimMessageBus.Host.Outbox.DbContext.Test/OutboxTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public record GenerateCustomerIdCommand(string Firstname, string Lastname) : IRe
310310

311311
public class GenerateCustomerIdCommandHandler : IRequestHandler<GenerateCustomerIdCommand, string>
312312
{
313-
public async Task<string> OnHandle(GenerateCustomerIdCommand request, CancellationToken cancellationToken)
313+
public Task<string> OnHandle(GenerateCustomerIdCommand request, CancellationToken cancellationToken)
314314
{
315315
// Note: This handler will be already wrapped in a transaction: see Program.cs and .UseTransactionScope() / .UseSqlTransaction()
316316

0 commit comments

Comments
 (0)