-
Notifications
You must be signed in to change notification settings - Fork 160
/
HystrixRabbitMQServiceInfoFactory.cs
60 lines (50 loc) · 1.99 KB
/
HystrixRabbitMQServiceInfoFactory.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
// 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 Steeltoe.Extensions.Configuration;
using System.Collections.Generic;
namespace Steeltoe.Connector.Services;
public class HystrixRabbitMQServiceInfoFactory : ServiceInfoFactory
{
public static readonly Tags HYSTRIX_RABBIT_SERVICE_TAGS = new ("hystrix-amqp");
private static readonly string[] _scheme = new string[] { RabbitMQServiceInfo.AMQP_SCHEME, RabbitMQServiceInfo.AMQPS_SCHEME };
public HystrixRabbitMQServiceInfoFactory()
: base(HYSTRIX_RABBIT_SERVICE_TAGS, _scheme)
{
}
public override bool Accepts(Service binding)
{
return TagsMatch(binding) && UriCredentialsMatchesScheme(binding.Credentials);
}
public override IServiceInfo Create(Service binding)
{
var amqpCredentials = binding.Credentials["amqp"];
var uri = GetUriFromCredentials(amqpCredentials);
var sslEnabled = GetBoolFromCredentials(amqpCredentials, "ssl");
if (amqpCredentials.ContainsKey("uris"))
{
var uris = GetListFromCredentials(amqpCredentials, "uris");
return new HystrixRabbitMQServiceInfo(binding.Name, uri, uris, sslEnabled);
}
return new HystrixRabbitMQServiceInfo(binding.Name, uri, sslEnabled);
}
private bool UriCredentialsMatchesScheme(Dictionary<string, Credential> credentials)
{
if (credentials.ContainsKey("amqp"))
{
var amqpDict = credentials["amqp"];
var uri = GetStringFromCredentials(amqpDict, UriKeys);
if (uri != null)
{
foreach (var uriScheme in UriSchemes)
{
if (uri.StartsWith(uriScheme + "://"))
{
return true;
}
}
}
}
return false;
}
}