Реализовать лабораторную работу 5

This commit is contained in:
Никита
2026-11-10 10:57:36 +03:00
parent 276dbdad8a
commit 8c87c60621
124 changed files with 15887 additions and 27 deletions
@@ -0,0 +1,21 @@
using RabbitMQ.Client;
namespace Messenger.Api.Pipeline;
public static class BrokerConnection
{
public const string Queue="attachments.v1";
public static Task<IConnection> 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<string,object?> {
["x-queue-type"]="quorum",["x-max-length"]=256,["x-overflow"]="reject-publish"
},cancellationToken:ct);
}