forked from mtusi2026/mtusi2026lab5
22 lines
1.0 KiB
C#
22 lines
1.0 KiB
C#
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);
|
|
}
|