2021-11-28 13:18:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PettingZoo.Core.Connection
|
|
|
|
|
{
|
|
|
|
|
public interface IConnection : IAsyncDisposable
|
|
|
|
|
{
|
2022-01-30 10:12:35 +00:00
|
|
|
|
Guid ConnectionId { get; }
|
|
|
|
|
ConnectionParams? ConnectionParams { get; }
|
|
|
|
|
ConnectionStatus Status { get; }
|
|
|
|
|
|
2021-11-28 13:18:21 +00:00
|
|
|
|
event EventHandler<StatusChangedEventArgs> StatusChanged;
|
|
|
|
|
|
2022-01-30 10:12:35 +00:00
|
|
|
|
|
|
|
|
|
void Connect();
|
|
|
|
|
|
2021-11-28 13:18:21 +00:00
|
|
|
|
ISubscriber Subscribe(string exchange, string routingKey);
|
2021-12-18 11:18:35 +00:00
|
|
|
|
ISubscriber Subscribe();
|
|
|
|
|
|
2021-12-06 13:08:29 +00:00
|
|
|
|
Task Publish(PublishMessageInfo messageInfo);
|
2021-11-28 13:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum ConnectionStatus
|
|
|
|
|
{
|
|
|
|
|
Disconnected,
|
|
|
|
|
Connecting,
|
|
|
|
|
Connected,
|
|
|
|
|
Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class StatusChangedEventArgs : EventArgs
|
|
|
|
|
{
|
2022-01-30 10:12:35 +00:00
|
|
|
|
public Guid ConnectionId { get; }
|
2021-11-28 13:18:21 +00:00
|
|
|
|
public ConnectionStatus Status { get; }
|
2022-01-30 10:12:35 +00:00
|
|
|
|
public ConnectionParams? ConnectionParams { get; }
|
|
|
|
|
public Exception? Exception { get; }
|
2021-11-28 13:18:21 +00:00
|
|
|
|
|
|
|
|
|
|
2022-01-30 10:12:35 +00:00
|
|
|
|
public StatusChangedEventArgs(Guid connectionId, ConnectionStatus status, ConnectionParams? connectionParams = null, Exception? exception = null)
|
2021-11-28 13:18:21 +00:00
|
|
|
|
{
|
2022-01-30 10:12:35 +00:00
|
|
|
|
ConnectionId = connectionId;
|
2021-11-28 13:18:21 +00:00
|
|
|
|
Status = status;
|
2022-01-30 10:12:35 +00:00
|
|
|
|
ConnectionParams = connectionParams;
|
|
|
|
|
Exception = exception;
|
2021-11-28 13:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|