|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 2.0. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (c) 2007-2020 VMware, Inc. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v2.0: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 26 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 27 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 28 | +// |
| 29 | +// Copyright (c) 2007-2020 VMware, Inc. All rights reserved. |
| 30 | +//--------------------------------------------------------------------------- |
| 31 | + |
| 32 | +using System; |
| 33 | +using System.Collections.Generic; |
| 34 | + |
| 35 | +using RabbitMQ.Client.Impl; |
| 36 | + |
| 37 | +namespace RabbitMQ.Client |
| 38 | +{ |
| 39 | + #nullable enable |
| 40 | + /// <summary> |
| 41 | + /// The configuration of a connection. |
| 42 | + /// </summary> |
| 43 | + public sealed class ConnectionConfig |
| 44 | + { |
| 45 | + /// <summary> |
| 46 | + /// Virtual host to access during this connection. |
| 47 | + /// </summary> |
| 48 | + public string VirtualHost { get; } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Username to use when authenticating to the server. |
| 52 | + /// </summary> |
| 53 | + public string UserName { get; } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Password to use when authenticating to the server. |
| 57 | + /// </summary> |
| 58 | + public string Password { get; internal set; } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// SASL auth mechanisms to use. |
| 62 | + /// </summary> |
| 63 | + public IList<IAuthMechanismFactory> AuthMechanisms { get; } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Dictionary of client properties to be sent to the server. |
| 67 | + /// </summary> |
| 68 | + public IDictionary<string, object?> ClientProperties { get; } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Default client provided name to be used for connections. |
| 72 | + /// </summary> |
| 73 | + public string? ClientProvidedName { get; } |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Maximum channel number to ask for. |
| 77 | + /// </summary> |
| 78 | + public ushort MaxChannelCount { get; } |
| 79 | + /// <summary> |
| 80 | + /// Frame-max parameter to ask for (in bytes). |
| 81 | + /// </summary> |
| 82 | + public uint MaxFrameSize { get; } |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Set to false to make automatic connection recovery not recover topology (exchanges, queues, bindings, etc). |
| 86 | + /// </summary> |
| 87 | + public bool TopologyRecoveryEnabled { get; } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Amount of time client will wait for before re-trying to recover connection. |
| 91 | + /// </summary> |
| 92 | + public TimeSpan NetworkRecoveryInterval { get; } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Heartbeat timeout to use when negotiating with the server. |
| 96 | + /// </summary> |
| 97 | + public TimeSpan HeartbeatInterval { get; } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Amount of time protocol operations (e.g. <code>queue.declare</code>) are allowed to take before timing out. |
| 101 | + /// </summary> |
| 102 | + public TimeSpan ContinuationTimeout { get; } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Amount of time protocol handshake operations are allowed to take before timing out. |
| 106 | + /// </summary> |
| 107 | + |
| 108 | + public TimeSpan HandshakeContinuationTimeout { get; } |
| 109 | + /// <summary> |
| 110 | + /// Timeout setting for connection attempts. |
| 111 | + /// </summary> |
| 112 | + public TimeSpan RequestedConnectionTimeout { get; } |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Set to true will enable an asynchronous consumer dispatcher which is compatible with <see cref="IAsyncBasicConsumer"/>. |
| 116 | + /// </summary> |
| 117 | + public bool DispatchConsumersAsync { get; } |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Set to a value greater than one to enable concurrent processing. For a concurrency greater than one <see cref="IBasicConsumer"/> |
| 121 | + /// will be offloaded to the worker thread pool so it is important to choose the value for the concurrency wisely to avoid thread pool overloading. |
| 122 | + /// <see cref="IAsyncBasicConsumer"/> can handle concurrency much more efficiently due to the non-blocking nature of the consumer. |
| 123 | + /// </summary> |
| 124 | + public int DispatchConsumerConcurrency { get; } |
| 125 | + |
| 126 | + internal Func<AmqpTcpEndpoint, IFrameHandler> FrameHandlerFactory { get; } |
| 127 | + |
| 128 | + internal ConnectionConfig(string virtualHost, string userName, string password, IList<IAuthMechanismFactory> authMechanisms, |
| 129 | + IDictionary<string, object?> clientProperties, string? clientProvidedName, |
| 130 | + ushort maxChannelCount, uint maxFrameSize, bool topologyRecoveryEnabled, |
| 131 | + TimeSpan networkRecoveryInterval, TimeSpan heartbeatInterval, TimeSpan continuationTimeout, TimeSpan handshakeContinuationTimeout, TimeSpan requestedConnectionTimeout, |
| 132 | + bool dispatchConsumersAsync, int dispatchConsumerConcurrency, |
| 133 | + Func<AmqpTcpEndpoint, IFrameHandler> frameHandlerFactory) |
| 134 | + { |
| 135 | + VirtualHost = virtualHost; |
| 136 | + UserName = userName; |
| 137 | + Password = password; |
| 138 | + AuthMechanisms = authMechanisms; |
| 139 | + ClientProperties = clientProperties; |
| 140 | + ClientProvidedName = clientProvidedName; |
| 141 | + MaxChannelCount = maxChannelCount; |
| 142 | + MaxFrameSize = maxFrameSize; |
| 143 | + TopologyRecoveryEnabled = topologyRecoveryEnabled; |
| 144 | + NetworkRecoveryInterval = networkRecoveryInterval; |
| 145 | + HeartbeatInterval = heartbeatInterval; |
| 146 | + ContinuationTimeout = continuationTimeout; |
| 147 | + HandshakeContinuationTimeout = handshakeContinuationTimeout; |
| 148 | + RequestedConnectionTimeout = requestedConnectionTimeout; |
| 149 | + DispatchConsumersAsync = dispatchConsumersAsync; |
| 150 | + DispatchConsumerConcurrency = dispatchConsumerConcurrency; |
| 151 | + FrameHandlerFactory = frameHandlerFactory; |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments