using System; using Tapeti.Config; // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMemberInSuper.Global namespace Tapeti { /// /// Contains information about the connection being established. /// public interface IConnectContext { /// /// The connection parameters used to establish the connection. /// TapetiConnectionParams ConnectionParams { get; } /// /// Indicates whether this is an automatic reconnect or an initial connection. /// bool IsReconnect { get; } } /// /// /// Contains information about the failed connection. /// public interface IConnectFailedContext : IConnectContext { /// /// The exception that caused the connection to fail. /// Exception Exception { get; } } /// /// /// Contains information about the established connection. /// public interface IConnectSuccessContext : IConnectContext { /// /// The local port for the connection. Useful for identifying the connection in the management interface. /// int LocalPort { get; } } /// /// Contains information about the disconnection. /// public interface IDisconnectContext { /// /// The connection parameters used to establish the connection. /// TapetiConnectionParams ConnectionParams { get; } /// /// The reply code as provided by RabbitMQ, if the connection was closed by a protocol message. /// ushort ReplyCode { get; } /// /// The reply text as provided by RabbitMQ, if the connection was closed by a protocol message. /// string ReplyText { get; } } /// /// Handles the logging of various events in Tapeti /// /// /// This interface is deliberately specific and typed to allow for structured logging (e.g. Serilog) /// instead of only string-based logging without control over the output. /// public interface ILogger { /// /// Called before a connection to RabbitMQ is attempted. /// /// Contains information about the connection being established. void Connect(IConnectContext connectContext); /// /// Called when the connection has failed. /// /// Contains information about the connection that has failed. void ConnectFailed(IConnectFailedContext connectContext); /// /// Called when a connection to RabbitMQ has been succesfully established. /// /// Contains information about the established connection. void ConnectSuccess(IConnectSuccessContext connectContext); /// /// Called when the connection to RabbitMQ is lost. /// /// Contains information about the disconnect event. void Disconnect(IDisconnectContext disconnectContext); /// /// Called when an exception occurs in a consumer. /// /// /// /// Indicates the action taken by the exception handler void ConsumeException(Exception exception, IMessageContext messageContext, ConsumeResult consumeResult); } /// /// Optional interface which can be implemented by an ILogger implementation to log all operations /// related to declaring queues and bindings. /// public interface IBindingLogger : ILogger { /// /// Called before a queue is declared for durable queues and dynamic queues with a prefix. Called after /// a queue is declared for dynamic queues without a name with the queue name as determined by the RabbitMQ server. /// Will always be called even if the queue already existed, as that information is not returned by the RabbitMQ server/client. /// /// The name of the queue that is declared /// Indicates if the queue is durable or dynamic /// Indicates whether the queue was declared as passive (to verify durable queues) void QueueDeclare(string queueName, bool durable, bool passive); /// /// Called before a binding is added to a queue. /// /// The name of the queue the binding is created for /// Indicates if the queue is durable or dynamic /// The exchange for the binding /// The routing key for the binding void QueueBind(string queueName, bool durable, string exchange, string routingKey); /// /// Called before a binding is removed from a durable queue. /// /// The name of the queue the binding is removed from /// The exchange of the binding /// The routing key of the binding void QueueUnbind(string queueName, string exchange, string routingKey); /// /// Called before an exchange is declared. Will always be called once for each exchange involved in a dynamic queue, /// durable queue with auto-declare bindings enabled or published messages, even if the exchange already existed. /// /// The name of the exchange that is declared void ExchangeDeclare(string exchange); /// /// Called when a queue is determined to be obsolete. /// /// /// True if the queue was empty and has been deleted, false if there are still messages to process /// If deleted, the number of messages purged, otherwise the number of messages still in the queue void QueueObsolete(string queueName, bool deleted, uint messageCount); } }