using RabbitMQ.Client; namespace Messenger.Api.Pipeline; public static class BrokerConnection { public const string Queue="attachments.v1"; public static Task OpenAsync(IConfiguration config,CancellationToken ct) { var factory=new ConnectionFactory { HostName=config["BROKER_HOST"]??"broker", UserName="messenger", Password=File.ReadAllText(config["BROKER_PASSWORD_FILE"]!).Trim(), VirtualHost="messenger",AutomaticRecoveryEnabled=true, NetworkRecoveryInterval=TimeSpan.FromSeconds(2),RequestedHeartbeat=TimeSpan.FromSeconds(10), RequestedConnectionTimeout=TimeSpan.FromSeconds(5) }; return factory.CreateConnectionAsync(ct); } public static Task DeclareAsync(IChannel channel,CancellationToken ct)=>channel.QueueDeclareAsync( Queue,durable:true,exclusive:false,autoDelete:false,arguments:new Dictionary { ["x-queue-type"]="quorum",["x-max-length"]=256,["x-overflow"]="reject-publish" },cancellationToken:ct); }