Skip to content

Commit

Permalink
Allow injection of custom implementation of IPersistentConnection (Ea…
Browse files Browse the repository at this point in the history
…syNetQ#614)

* added the PersistentConnectionFactory

* updated version.cs
  • Loading branch information
jweibel22 authored and micdenny committed Sep 26, 2016
1 parent fa6557e commit e2b7596
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Source/EasyNetQ.Tests/AdvancedBusEventHandlersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ public void SetUp()

eventBus = new EventBus();

var logger = MockRepository.GenerateStub<IEasyNetQLogger>();
var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus);

var advancedBus = new RabbitAdvancedBus(
connectionFactory,
MockRepository.GenerateStub<IConsumerFactory>(),
MockRepository.GenerateStub<IEasyNetQLogger>(),
logger,
MockRepository.GenerateStub<IClientCommandDispatcherFactory>(),
MockRepository.GenerateStub<IPublishConfirmationListener>(),
eventBus,
Expand All @@ -61,7 +64,8 @@ public void SetUp()
MockRepository.GenerateStub<IProduceConsumeInterceptor>(),
MockRepository.GenerateStub<IMessageSerializationStrategy>(),
MockRepository.GenerateStub<IConventions>(),
advancedBusEventHandlers);
advancedBusEventHandlers,
persistentConnectionFactory);
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions Source/EasyNetQ/ComponentRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void RegisterServices(IContainer container)
.Register<IConsumerFactory, ConsumerFactory>()
.Register<IConnectionFactory, ConnectionFactoryWrapper>()
.Register<IPersistentChannelFactory, PersistentChannelFactory>()
.Register<IPersistentConnectionFactory, PersistentConnectionFactory>()
.Register<IClientCommandDispatcherFactory, ClientCommandDispatcherFactory>()
.Register<IPublishConfirmationListener, PublishConfirmationListener>()
.Register<IHandlerCollectionFactory, HandlerCollectionFactory>()
Expand Down
2 changes: 2 additions & 0 deletions Source/EasyNetQ/EasyNetQ.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Interception\IProduceConsumeInterceptor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interception\RawMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interception\TripleDESInterceptor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IPersistentConnectionFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ISerializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IServiceProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ISubscriptionResult.cs" />
Expand All @@ -118,6 +119,7 @@
<Compile Include="$(MSBuildThisFileDirectory)NonGeneric\NonGenericExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OrderedClusterHostSelectionStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PersistentConnection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PersistentConnectionFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Preconditions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Producer\ClientCommandDispatcher.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Producer\ClientCommandDispatcherSingleton.cs" />
Expand Down
7 changes: 7 additions & 0 deletions Source/EasyNetQ/IPersistentConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EasyNetQ
{
public interface IPersistentConnectionFactory
{
IPersistentConnection CreateConnection();
}
}
25 changes: 25 additions & 0 deletions Source/EasyNetQ/PersistentConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EasyNetQ
{
public class PersistentConnectionFactory : IPersistentConnectionFactory
{
private readonly IEventBus eventBus;
private readonly IConnectionFactory connectionFactory;
private readonly IEasyNetQLogger logger;

public PersistentConnectionFactory(IEasyNetQLogger logger, IConnectionFactory connectionFactory, IEventBus eventBus)
{
this.logger = logger;
this.connectionFactory = connectionFactory;
this.eventBus = eventBus;
}

public IPersistentConnection CreateConnection()
{
return new PersistentConnection(connectionFactory, logger, eventBus);
}
}
}
6 changes: 4 additions & 2 deletions Source/EasyNetQ/RabbitAdvancedBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public RabbitAdvancedBus(
IProduceConsumeInterceptor produceConsumeInterceptor,
IMessageSerializationStrategy messageSerializationStrategy,
IConventions conventions,
AdvancedBusEventHandlers advancedBusEventHandlers)
AdvancedBusEventHandlers advancedBusEventHandlers,
IPersistentConnectionFactory persistentConnectionFactory)
{
Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
Preconditions.CheckNotNull(consumerFactory, "consumerFactory");
Expand All @@ -53,6 +54,7 @@ public RabbitAdvancedBus(
Preconditions.CheckNotNull(produceConsumeInterceptor, "produceConsumeInterceptor");
Preconditions.CheckNotNull(conventions, "conventions");
Preconditions.CheckNotNull(advancedBusEventHandlers, "advancedBusEventHandlers");
Preconditions.CheckNotNull(persistentConnectionFactory, "persistentConnectionFactory");

this.consumerFactory = consumerFactory;
this.logger = logger;
Expand Down Expand Up @@ -91,7 +93,7 @@ public RabbitAdvancedBus(
MessageReturned += advancedBusEventHandlers.MessageReturned;
}

connection = new PersistentConnection(connectionFactory, logger, eventBus);
connection = persistentConnectionFactory.CreateConnection();
clientCommandDispatcher = clientCommandDispatcherFactory.GetClientCommandDispatcher(connection);
connection.Initialize();
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

// EasyNetQ version number: <major>.<minor>.<non-breaking-feature>.<build>
// Note: until version 1.0 expect breaking changes on 0.X versions.
[assembly: AssemblyVersion("0.63.1.0")]
[assembly: AssemblyVersion("0.63.3.0")]
[assembly: CLSCompliant(false)]

// Note: until version 1.0 expect breaking changes on 0.X versions.
// 0.63.3.0 Allow injection of custom implementation of IPersistentConnection
// 0.63.2.0 Make SimpleInjectorMessageDispatcher public so it can be used with AutoSubscriber
// 0.63.1.0 Set upper bound of supported rabbitmq client version
// 0.63.0.0 Make ConnectIntervalAttempt for PersistentConnection configurable on ConnectionConfiguration
Expand Down

0 comments on commit e2b7596

Please sign in to comment.