/
HystrixProviderConnectorOptions.cs
71 lines (54 loc) · 1.91 KB
/
HystrixProviderConnectorOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using Microsoft.Extensions.Configuration;
using Steeltoe.Connector.Services;
using System;
namespace Steeltoe.Connector.Hystrix;
public class HystrixProviderConnectorOptions : AbstractServiceConnectorOptions
{
public const string Default_Scheme = "amqp";
public const string Default_SSLScheme = "amqps";
public const string Default_Server = "127.0.0.1";
public const int Default_Port = 5672;
public const int Default_SSLPort = 5671;
private const string HYSTRIX_CLIENT_SECTION_PREFIX = "hystrix:client";
public HystrixProviderConnectorOptions()
{
}
public HystrixProviderConnectorOptions(IConfiguration config)
: base()
{
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
var section = config.GetSection(HYSTRIX_CLIENT_SECTION_PREFIX);
section.Bind(this);
}
public bool SslEnabled { get; set; } = false;
public string Uri { get; set; }
public string Server { get; set; } = Default_Server;
public int Port { get; set; } = Default_Port;
public int SslPort { get; set; } = Default_SSLPort;
public string Username { get; set; }
public string Password { get; set; }
public string VirtualHost { get; set; }
public override string ToString()
{
if (!string.IsNullOrEmpty(Uri))
{
return Uri;
}
UriInfo uri;
if (SslEnabled)
{
uri = new UriInfo(Default_SSLScheme, Server, SslPort, Username, Password, VirtualHost);
}
else
{
uri = new UriInfo(Default_Scheme, Server, Port, Username, Password, VirtualHost);
}
return uri.ToString();
}
}