// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
// ReSharper disable once CheckNamespace
namespace DotNetCore.CAP;
// ReSharper disable once InconsistentNaming
public class RabbitMQOptions
{
///
/// Default password (value: "guest").
///
/// PLEASE KEEP THIS MATCHING THE DOC ABOVE.
public const string DefaultPass = "guest";
///
/// Default user name (value: "guest").
///
/// PLEASE KEEP THIS MATCHING THE DOC ABOVE.
public const string DefaultUser = "guest";
///
/// Default virtual host (value: "/").
///
/// PLEASE KEEP THIS MATCHING THE DOC ABOVE.
public const string DefaultVHost = "/";
///
/// Default exchange name (value: "cap.default.router").
///
public const string DefaultExchangeName = "cap.default.router";
/// The topic exchange type.
public const string ExchangeType = "topic";
///
/// The host to connect to.
/// If you want to connect to the cluster, you can assign like “192.168.1.111,192.168.1.112”
///
public string HostName { get; set; } = "localhost";
///
/// Password to use when authenticating to the server.
///
public string Password { get; set; } = DefaultPass;
///
/// Username to use when authenticating to the server.
///
public string UserName { get; set; } = DefaultUser;
///
/// Virtual host to access during this connection.
///
public string VirtualHost { get; set; } = DefaultVHost;
///
/// Topic exchange name when declare a topic exchange.
///
public string ExchangeName { get; set; } = DefaultExchangeName;
///
/// Enabling Publisher Confirms on a Channel
///
public bool PublishConfirms { get; set; }
///
/// The port to connect on.
///
public int Port { get; set; } = -1;
///
/// Optional queue arguments, also known as "x-arguments" because of their field name in the AMQP 0-9-1 protocol,
/// is a map (dictionary) of arbitrary key/value pairs that can be provided by clients when a queue is declared.
///
public QueueArgumentsOptions QueueArguments { get; set; } = new();
///
/// Optional queue arguments, also known as "x-arguments" because of their field name in the AMQP 0-9-1 protocol,
/// is a map (dictionary) of arbitrary key/value pairs that can be provided by clients when a queue is declared.
///
public QueueRabbitOptions QueueOptions { get; set; } = new();
///
/// If you need to get additional native delivery args, you can use this function to write into .
///
public Func>>? CustomHeadersBuilder
{
get;
set;
}
///
/// RabbitMQ native connection factory options
///
public Action? ConnectionFactoryOptions { get; set; }
///
/// Specify quality of service.
///
/// These settings request a specific quality of service.The QoS can be specified for the current channel or for all
/// channels on the connection.
/// The particular properties and semantics of a qos method always depend on the content class semantics.
/// Though the qos method could in principle apply to both peers, it is currently meaningful only for the server.
///
///
/// More info at:
/// https://www.rabbitmq.com/consumer-prefetch.html
///
///
public BasicQos? BasicQosOptions { get; set; } = null;
public class QueueArgumentsOptions
{
///
/// Gets or sets queue mode by supplying the 'x-queue-mode' declaration argument with a string specifying the desired mode.
///
public string QueueMode { get; set; } = null!;
///
/// Gets or sets queue message automatic deletion time (in milliseconds) "x-message-ttl", Default 864000000 ms (10 days).
///
// ReSharper disable once InconsistentNaming
public int MessageTTL { get; set; } = 864000000;
///
/// Gets or sets queue type by supplying the 'x-queue-type' declaration argument with a string specifying the desired type.
///
public string QueueType { get; set; } = null!;
}
public class BasicQos
{
///
/// New instance of BasicQos sets the use of basic qos setup on the basic channel.
///
/// Sets the PrefetchCount.
/// Sets Global flag (default false).
public BasicQos(ushort prefetchCount, bool global = false)
{
PrefetchCount = prefetchCount;
Global = global;
}
///
/// Gets the PrefetchCount, a value of 0 is treated as infinite, allowing any number of unacknowledged message being pushed
/// to consumer.
/// The default value is 0.
///
public ushort PrefetchCount { get; }
///
/// Gets the global flag across all consumers in RabbitMq.
/// false (default) - applied separately to each new consumer on the channel
/// true - shared across all consumers on the channel
///
public bool Global { get; }
}
public class QueueRabbitOptions
{
public bool Durable { get; set; } = true;
public bool Exclusive { get; set; } = false;
public bool AutoDelete { get; set; } = false;
}
}