1
0
mirror of synced 2024-11-16 14:53:50 +00:00

Merge branch 'release/1.1.1'

This commit is contained in:
Mark van Renswoude 2019-01-08 16:37:31 +01:00
commit 7b4aa1660f
7 changed files with 36 additions and 24 deletions

View File

@ -1,8 +1,6 @@
using System; using System;
using ISeriLogger = Serilog.ILogger; using ISeriLogger = Serilog.ILogger;
// ReSharper disable UnusedMember.Global
namespace Tapeti.Serilog namespace Tapeti.Serilog
{ {
public class TapetiSeriLogger: ILogger public class TapetiSeriLogger: ILogger
@ -16,26 +14,31 @@ namespace Tapeti.Serilog
public void Connect(TapetiConnectionParams connectionParams) public void Connect(TapetiConnectionParams connectionParams)
{ {
// method not yet used in Tapeti seriLogger.Information("Tapeti: trying to connect to {host}:{port}/{virtualHost}",
seriLogger.Information("Trying to connected to " + connectionParams.HostName); connectionParams.HostName,
connectionParams.Port,
connectionParams.VirtualHost);
} }
public void ConnectFailed(TapetiConnectionParams connectionParams) public void ConnectFailed(TapetiConnectionParams connectionParams, Exception exception)
{ {
// method not yet used in Tapeti seriLogger.Error(exception, "Tapeti: could not connect to {host}:{port}/{virtualHost}",
seriLogger.Error("Could not connect to " + connectionParams.HostName); connectionParams.HostName,
connectionParams.Port,
connectionParams.VirtualHost);
} }
public void ConnectSuccess(TapetiConnectionParams connectionParams) public void ConnectSuccess(TapetiConnectionParams connectionParams)
{ {
// method not yet used in Tapeti seriLogger.Information("Tapeti: successfully connected to {host}:{port}/{virtualHost}",
seriLogger.Information("Succesfull connected to " + connectionParams.HostName); connectionParams.HostName,
connectionParams.Port,
connectionParams.VirtualHost);
} }
public void HandlerException(Exception e) public void HandlerException(Exception e)
{ {
seriLogger.Error(e, "Exception handled by Tapeti"); seriLogger.Error(e, "Tapeti: exception in message handler");
} }
} }
} }

View File

@ -16,6 +16,7 @@ namespace Tapeti.Connection
private const int PublishMaxConnectAttempts = 3; private const int PublishMaxConnectAttempts = 3;
private readonly IConfig config; private readonly IConfig config;
private readonly ILogger logger;
public TapetiConnectionParams ConnectionParams { get; set; } public TapetiConnectionParams ConnectionParams { get; set; }
public IConnectionEventListener ConnectionEventListener { get; set; } public IConnectionEventListener ConnectionEventListener { get; set; }
@ -31,6 +32,7 @@ namespace Tapeti.Connection
{ {
this.config = config; this.config = config;
logger = config.DependencyResolver.Resolve<ILogger>();
messageSerializer = config.DependencyResolver.Resolve<IMessageSerializer>(); messageSerializer = config.DependencyResolver.Resolve<IMessageSerializer>();
routingKeyStrategy = config.DependencyResolver.Resolve<IRoutingKeyStrategy>(); routingKeyStrategy = config.DependencyResolver.Resolve<IRoutingKeyStrategy>();
exchangeStrategy = config.DependencyResolver.Resolve<IExchangeStrategy>(); exchangeStrategy = config.DependencyResolver.Resolve<IExchangeStrategy>();
@ -201,6 +203,8 @@ namespace Tapeti.Connection
{ {
try try
{ {
logger.Connect(ConnectionParams);
connection = connectionFactory.CreateConnection(); connection = connectionFactory.CreateConnection();
channelInstance = connection.CreateModel(); channelInstance = connection.CreateModel();
@ -212,10 +216,14 @@ namespace Tapeti.Connection
channelInstance.ModelShutdown += (sender, e) => ConnectionEventListener?.Disconnected(); channelInstance.ModelShutdown += (sender, e) => ConnectionEventListener?.Disconnected();
ConnectionEventListener?.Connected(); ConnectionEventListener?.Connected();
logger.ConnectSuccess(ConnectionParams);
break; break;
} }
catch (BrokerUnreachableException) catch (BrokerUnreachableException e)
{ {
logger.ConnectFailed(ConnectionParams, e);
attempts++; attempts++;
if (maxAttempts.HasValue && attempts > maxAttempts.Value) if (maxAttempts.HasValue && attempts > maxAttempts.Value)
throw; throw;

View File

@ -6,17 +6,17 @@ namespace Tapeti.Default
{ {
public void Connect(TapetiConnectionParams connectionParams) public void Connect(TapetiConnectionParams connectionParams)
{ {
throw new NotImplementedException(); Console.WriteLine($"[Tapeti] Connecting to {connectionParams.HostName}:{connectionParams.Port}{connectionParams.VirtualHost}");
} }
public void ConnectFailed(TapetiConnectionParams connectionParams) public void ConnectFailed(TapetiConnectionParams connectionParams, Exception exception)
{ {
throw new NotImplementedException(); Console.WriteLine($"[Tapeti] Connection failed: {exception}");
} }
public void ConnectSuccess(TapetiConnectionParams connectionParams) public void ConnectSuccess(TapetiConnectionParams connectionParams)
{ {
throw new NotImplementedException(); Console.WriteLine($"[Tapeti] Connected");
} }
public void HandlerException(Exception e) public void HandlerException(Exception e)

View File

@ -8,7 +8,7 @@ namespace Tapeti.Default
{ {
} }
public void ConnectFailed(TapetiConnectionParams connectionParams) public void ConnectFailed(TapetiConnectionParams connectionParams, Exception exception)
{ {
} }

View File

@ -9,7 +9,7 @@ namespace Tapeti
public interface ILogger public interface ILogger
{ {
void Connect(TapetiConnectionParams connectionParams); void Connect(TapetiConnectionParams connectionParams);
void ConnectFailed(TapetiConnectionParams connectionParams); void ConnectFailed(TapetiConnectionParams connectionParams, Exception exception);
void ConnectSuccess(TapetiConnectionParams connectionParams); void ConnectSuccess(TapetiConnectionParams connectionParams);
void HandlerException(Exception e); void HandlerException(Exception e);
} }

6
Test/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="rabbitmq:hostname" value="localhost" />
</appSettings>
</configuration>

View File

@ -1,25 +1,20 @@
using System; using System;
using Tapeti; using Tapeti;
// ReSharper disable UnusedMember.Global
namespace Test namespace Test
{ {
public class MyLogger : ILogger public class MyLogger : ILogger
{ {
public void Connect(TapetiConnectionParams connectionParams) public void Connect(TapetiConnectionParams connectionParams)
{ {
throw new NotImplementedException();
} }
public void ConnectFailed(TapetiConnectionParams connectionParams) public void ConnectFailed(TapetiConnectionParams connectionParams, Exception exception)
{ {
throw new NotImplementedException();
} }
public void ConnectSuccess(TapetiConnectionParams connectionParams) public void ConnectSuccess(TapetiConnectionParams connectionParams)
{ {
throw new NotImplementedException();
} }
public void HandlerException(Exception e) public void HandlerException(Exception e)