using System;
using System.Threading.Tasks;
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMemberInSuper.Global
namespace Tapeti
{
///
/// Contains information about the established connection.
///
public class ConnectedEventArgs
{
///
/// The connection parameters used to establish the connection.
///
public TapetiConnectionParams ConnectionParams { get; }
///
/// The local port for the connection. Useful for identifying the connection in the management interface.
///
public int LocalPort { get; }
///
public ConnectedEventArgs(TapetiConnectionParams connectionParams, int localPort)
{
ConnectionParams = connectionParams;
LocalPort = localPort;
}
}
///
/// Contains information about the reason for a lost connection.
///
public class DisconnectedEventArgs
{
///
/// The ReplyCode as indicated by the client library
///
public ushort ReplyCode { get; }
///
/// The ReplyText as indicated by the client library
///
public string ReplyText { get; }
///
public DisconnectedEventArgs(ushort replyCode, string replyText)
{
ReplyCode = replyCode;
ReplyText = replyText;
}
}
///
public delegate void ConnectedEventHandler(object sender, ConnectedEventArgs e);
///
public delegate void DisconnectedEventHandler(object sender, DisconnectedEventArgs e);
///
/// Represents a connection to a RabbitMQ server
///
public interface IConnection : IAsyncDisposable, IDisposable
{
///
/// Creates a subscriber to consume messages from the bound queues.
///
/// If true, the subscriber will start consuming messages immediately. If false, the queues will be
/// declared but no messages will be consumed yet. Call Resume on the returned ISubscriber to start consuming messages.
Task Subscribe(bool startConsuming = true);
///
/// Synchronous version of Subscribe.
///
/// If true, the subscriber will start consuming messages immediately. If false, the queues will be
/// declared but no messages will be consumed yet. Call Resume on the returned ISubscriber to start consuming messages.
ISubscriber SubscribeSync(bool startConsuming = true);
///
/// Returns an IPublisher implementation for the current connection.
///
///
IPublisher GetPublisher();
///
/// Closes the connection to RabbitMQ.
///
Task Close();
///
/// Fired when a connection to RabbitMQ has been established.
///
event ConnectedEventHandler Connected;
///
/// Fired when the connection to RabbitMQ has been lost.
///
event DisconnectedEventHandler Disconnected;
///
/// Fired when the connection to RabbitMQ has been recovered after an unexpected disconnect.
///
event ConnectedEventHandler Reconnected;
}
}