Skip to content

Commit 35d5928

Browse files
justmaraPliner
authored andcommitted
Using same ExchangeDeclareStrategy for publish and subscribe (#962)
* using same ExchangeDeclareStrategy for publish and subscribe * rename: PublishExchandeDeclareStrategy -> ExchangeDeclareStrategy * also renamed in tests and argiment constraints constants
1 parent 9ff1bcd commit 35d5928

16 files changed

+79
-80
lines changed

Source/EasyNetQ.Tests/MessageVersioningTests/MessageVersioningExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void When_using_EnableMessageVersioning_extension_method_required_service
1818

1919
serviceRegister.EnableMessageVersioning();
2020

21-
serviceRegister.AssertServiceRegistered<IPublishExchangeDeclareStrategy, VersionedPublishExchangeDeclareStrategy>();
21+
serviceRegister.AssertServiceRegistered<IExchangeDeclareStrategy, VersionedExchangeDeclareStrategy>();
2222
serviceRegister.AssertServiceRegistered<IMessageSerializationStrategy, VersionedMessageSerializationStrategy>();
2323
}
2424

Source/EasyNetQ.Tests/MessageVersioningTests/VersionedPublishExchangeDeclareStrategyTests.cs renamed to Source/EasyNetQ.Tests/MessageVersioningTests/VersionedExchangeDeclareStrategyTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace EasyNetQ.Tests.MessageVersioningTests
1313
{
14-
public class VersionedPublishExchangeDeclareStrategyTests
14+
public class VersionedExchangeDeclareStrategyTests
1515
{
1616
[Fact]
1717
public void Should_declare_exchange_again_if_first_attempt_failed()
@@ -33,16 +33,16 @@ public void Should_declare_exchange_again_if_first_attempt_failed()
3333
var conventions = Substitute.For<IConventions>();
3434
conventions.ExchangeNamingConvention = t => t.Name;
3535

36-
var publishExchangeDeclareStrategy = new VersionedPublishExchangeDeclareStrategy(conventions, advancedBus);
36+
var exchangeDeclareStrategy = new VersionedExchangeDeclareStrategy(conventions, advancedBus);
3737
try
3838
{
39-
publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
39+
exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
4040
}
4141
catch (Exception)
4242
{
4343
}
4444

45-
var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
45+
var declaredExchange = exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
4646
advancedBus.Received(2).ExchangeDeclare(exchangeName, "topic");
4747
declaredExchange.Should().BeSameAs(exchange);
4848
exchangeDeclareCount.Should().Be(1);
@@ -76,7 +76,7 @@ public void When_declaring_exchanges_for_unversioned_message_one_exchange_create
7676
var conventions = Substitute.For<IConventions>();
7777
conventions.ExchangeNamingConvention = t => t.Name;
7878

79-
var publishExchangeStrategy = new VersionedPublishExchangeDeclareStrategy(conventions, advancedBus);
79+
var publishExchangeStrategy = new VersionedExchangeDeclareStrategy(conventions, advancedBus);
8080

8181
publishExchangeStrategy.DeclareExchange(typeof(MyMessage), ExchangeType.Topic);
8282

@@ -111,7 +111,7 @@ public void When_declaring_exchanges_for_versioned_message_exchange_per_version_
111111
var conventions = Substitute.For<IConventions>();
112112
conventions.ExchangeNamingConvention = t => t.Name;
113113

114-
var publishExchangeStrategy = new VersionedPublishExchangeDeclareStrategy(conventions, advancedBus);
114+
var publishExchangeStrategy = new VersionedExchangeDeclareStrategy(conventions, advancedBus);
115115

116116
publishExchangeStrategy.DeclareExchange(typeof(MyMessageV2), ExchangeType.Topic);
117117

@@ -128,4 +128,4 @@ private class ExchangeStub : IExchange
128128
public ExchangeStub BoundTo { get; set; }
129129
}
130130
}
131-
}
131+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace EasyNetQ.Tests.MultipleExchangeTest
99
{
10-
public class AdvancedPolymorphismPublishExchangeDeclareStrategyTests
10+
public class AdvancedPolymorphismExchangeDeclareStrategyTests
1111
{
1212
[Fact(Skip = "Needs to be updated to XUnit")]
1313
public void When_declaring_exchanges_for_message_type_that_has_no_interface_one_exchange_created()
@@ -32,9 +32,9 @@ public void When_declaring_exchanges_for_message_type_that_has_no_interface_one_
3232
var conventions = Substitute.For<IConventions>();
3333
conventions.ExchangeNamingConvention = t => t.Name;
3434

35-
var publishExchangeStrategy = new MultipleExchangePublishExchangeDeclareStrategy(conventions, advancedBus);
35+
var exchangeStrategy = new MultipleExchangeDeclareStrategy(conventions, advancedBus);
3636

37-
publishExchangeStrategy.DeclareExchangeAsync(typeof(MyMessage), ExchangeType.Topic).Wait();
37+
exchangeStrategy.DeclareExchangeAsync(typeof(MyMessage), ExchangeType.Topic).Wait();
3838

3939
/*
4040
//ensure that only one exchange is declared
@@ -145,4 +145,4 @@ public void When_declaring_exchanges_for_message_with_two_interfaces_exchange_pe
145145
Arg<string>.Is.Anything), opt => opt.Repeat.Times(1));*/
146146
}
147147
}
148-
}
148+
}

Source/EasyNetQ.Tests/ProducerTests/PublishExchangeDeclareStrategyTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace EasyNetQ.Tests.ProducerTests
1212
{
13-
public class PublishExchangeDeclareStrategyTests
13+
public class ExchangeDeclareStrategyTests
1414
{
1515
private const string exchangeName = "the_exchange";
1616

@@ -27,9 +27,9 @@ public void Should_declare_exchange_the_first_time_declare_is_called()
2727
return exchange;
2828
});
2929

30-
var publishExchangeDeclareStrategy = new PublishExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
30+
var exchangeDeclareStrategy = new DefaultExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
3131

32-
var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
32+
var declaredExchange = exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
3333

3434
advancedBus.Received().ExchangeDeclare(exchangeName, "topic");
3535
declaredExchange.Should().BeSameAs(exchange);
@@ -48,10 +48,10 @@ public void Should_not_declare_exchange_the_second_time_declare_is_called()
4848
return exchange;
4949
});
5050

51-
var publishExchangeDeclareStrategy = new PublishExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
51+
var exchangeDeclareStrategy = new DefaultExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
5252

53-
var _ = publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
54-
var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
53+
var _ = exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
54+
var declaredExchange = exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
5555

5656
advancedBus.Received().ExchangeDeclare(exchangeName, "topic");
5757
declaredExchange.Should().BeSameAs(exchange);
@@ -74,20 +74,20 @@ public void Should_declare_exchange_again_if_first_attempt_failed()
7474
return exchange;
7575
});
7676

77-
var publishExchangeDeclareStrategy = new VersionedPublishExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
77+
var exchangeDeclareStrategy = new VersionedExchangeDeclareStrategy(Substitute.For<IConventions>(), advancedBus);
7878
try
7979
{
80-
publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
80+
exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
8181
}
8282
catch (Exception)
8383
{
8484
}
85-
var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
85+
var declaredExchange = exchangeDeclareStrategy.DeclareExchange(exchangeName, ExchangeType.Topic);
8686
advancedBus.Received(2).ExchangeDeclare(exchangeName, "topic");
8787
declaredExchange.Should().BeSameAs(exchange);
8888
exchangeDeclareCount.Should().Be(1);
8989
}
9090
}
9191
}
9292

93-
// ReSharper restore InconsistentNaming
93+
// ReSharper restore InconsistentNaming

Source/EasyNetQ/DI/DefaultServicesRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void RegisterDefaultServices(this IServiceRegister container)
3232
.Register(AdvancedBusEventHandlers.Default)
3333
.Register<IProduceConsumeInterceptor, DefaultInterceptor>()
3434
.Register<IConsumerDispatcherFactory, ConsumerDispatcherFactory>()
35-
.Register<IPublishExchangeDeclareStrategy, PublishExchangeDeclareStrategy>()
35+
.Register<IExchangeDeclareStrategy, DefaultExchangeDeclareStrategy>()
3636
.Register<IConsumerErrorStrategy, DefaultConsumerErrorStrategy>()
3737
.Register<IErrorMessageSerializer, DefaultErrorMessageSerializer>()
3838
.Register<IHandlerRunner, HandlerRunner>()

Source/EasyNetQ/MessageVersioning/ISupersede.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace EasyNetQ.MessageVersioning
66
/// Marker interface to indicate that a message supersedes a previous version.
77
/// </summary>
88
/// <remarks>
9-
/// Requires that <see cref="VersionedMessageSerializationStrategy"/> and <see cref="VersionedPublishExchangeDeclareStrategy"/> are
9+
/// Requires that <see cref="VersionedMessageSerializationStrategy"/> and <see cref="VersionedExchangeDeclareStrategy"/> are
1010
/// registered in the <see cref="IServiceRegister"/> to take advantage of message version support.
1111
/// </remarks>
1212
/// <typeparam name="T">The type of the message being superseded.</typeparam>

Source/EasyNetQ/MessageVersioning/MessageVersioningExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public static class MessageVersioningExtensions
88
public static IServiceRegister EnableMessageVersioning( this IServiceRegister serviceRegister )
99
{
1010
return serviceRegister
11-
.Register<IPublishExchangeDeclareStrategy, VersionedPublishExchangeDeclareStrategy>()
11+
.Register<IExchangeDeclareStrategy, VersionedExchangeDeclareStrategy>()
1212
.Register<IMessageSerializationStrategy, VersionedMessageSerializationStrategy>();
1313
}
1414
}
15-
}
15+
}

Source/EasyNetQ/MessageVersioning/VersionedPublishExchangeDeclareStrategy.cs renamed to Source/EasyNetQ/MessageVersioning/VersionedExchangeDeclareStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
namespace EasyNetQ.MessageVersioning
99
{
10-
public class VersionedPublishExchangeDeclareStrategy : IPublishExchangeDeclareStrategy
10+
public class VersionedExchangeDeclareStrategy : IExchangeDeclareStrategy
1111
{
1212
private readonly IAdvancedBus advancedBus;
1313
private readonly AsyncLock asyncLock = new AsyncLock();
1414
private readonly IConventions conventions;
1515
private readonly ConcurrentDictionary<string, IExchange> exchanges = new ConcurrentDictionary<string, IExchange>();
1616

17-
public VersionedPublishExchangeDeclareStrategy(IConventions conventions, IAdvancedBus advancedBus)
17+
public VersionedExchangeDeclareStrategy(IConventions conventions, IAdvancedBus advancedBus)
1818
{
1919
Preconditions.CheckNotNull(conventions, "conventions");
2020
Preconditions.CheckNotNull(advancedBus, "advancedBus");
@@ -90,4 +90,4 @@ private IExchange DeclareVersionedExchanges(MessageVersionStack messageVersions,
9090
return destinationExchange;
9191
}
9292
}
93-
}
93+
}

Source/EasyNetQ/MultipleExchange/MultipleExchangePublishExchangeDeclareStrategy.cs renamed to Source/EasyNetQ/MultipleExchange/MultipleExchangeDeclareStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
namespace EasyNetQ.MultipleExchange
99
{
10-
public class MultipleExchangePublishExchangeDeclareStrategy : IPublishExchangeDeclareStrategy
10+
public class MultipleExchangeDeclareStrategy : IExchangeDeclareStrategy
1111
{
1212
private readonly IAdvancedBus advancedBus;
1313
private readonly AsyncLock asyncLock = new AsyncLock();
1414
private readonly IConventions conventions;
1515
private readonly ConcurrentDictionary<string, IExchange> exchanges = new ConcurrentDictionary<string, IExchange>();
1616

17-
public MultipleExchangePublishExchangeDeclareStrategy(IConventions conventions, IAdvancedBus advancedBus)
17+
public MultipleExchangeDeclareStrategy(IConventions conventions, IAdvancedBus advancedBus)
1818
{
1919
Preconditions.CheckNotNull(conventions, "conventions");
2020
Preconditions.CheckNotNull(advancedBus, "advancedBus");
@@ -81,4 +81,4 @@ public async Task<IExchange> DeclareExchangeAsync(string exchangeName, string ex
8181
}
8282
}
8383
}
84-
}
84+
}

Source/EasyNetQ/MultipleExchange/MultipleExchangeExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class MultipleExchangeExtension
88
public static IServiceRegister EnableAdvancedMessagePolymorphism(this IServiceRegister serviceRegister)
99
{
1010
return serviceRegister
11-
.Register<IPublishExchangeDeclareStrategy, MultipleExchangePublishExchangeDeclareStrategy>();
11+
.Register<IExchangeDeclareStrategy, MultipleExchangeDeclareStrategy>();
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)