Skip to content

Commit 32efd54

Browse files
authored
CDMS-1223 - Refactors routing to use queue-only destinations (#251)
* Refactors routing to use queue-only destinations Eliminates the LinkType enum and removes logic for distinguishing between URL and Queue routing. All primary message routing now exclusively uses the queue sender. Removes the direct HTTP API sending path from the MessageRouter and ApiSender, simplifying the overall message flow. Streamlines configuration by removing LinkType properties from routing records and appsettings. Updates health checks to consider all named links. Removes the unused CdsAlvs endpoint configuration. Relates to CDMS-1223 * fixed merge issue
1 parent 406c24d commit 32efd54

19 files changed

+27
-435
lines changed

BtmsGateway/Middleware/RoutingInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private async Task Route(HttpContext context, MessageData messageData, IMetrics
101101

102102
RecordRequest(routingResult, RouteAction);
103103

104-
if (routingResult.RouteFound && routingResult.RouteLinkType != LinkType.None)
104+
if (routingResult.RouteFound)
105105
LogRouteFoundResults(messageData, routingResult, RouteAction);
106106
else
107107
LogRouteNotFoundResults(messageData, routingResult, RouteAction);

BtmsGateway/Services/Health/ConfigureHealthChecks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static IHealthChecksBuilder AddTopicChecks(this IHealthChecksBuilder bui
5959
if (routingConfig == null || routingConfig.AutomatedHealthCheckDisabled)
6060
return builder;
6161

62-
foreach (var queues in routingConfig.NamedLinks.Where(x => x.Value.LinkType == LinkType.Queue))
62+
foreach (var queues in routingConfig.NamedLinks)
6363
{
6464
builder.AddTypeActivatedCheck<TopicHealthCheck>(
6565
queues.Key,

BtmsGateway/Services/Routing/ApiSender.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System.Net;
21
using System.Text;
3-
using BtmsGateway.Middleware;
42
using BtmsGateway.Utils.Http;
53

64
namespace BtmsGateway.Services.Routing;
75

86
public interface IApiSender
97
{
10-
Task<RoutingResult> Send(RoutingResult routingResult, MessageData messageData);
118
Task<HttpResponseMessage> SendSoapMessageAsync(
129
string method,
1310
string destination,
@@ -21,34 +18,6 @@ CancellationToken cancellationToken
2118

2219
public class ApiSender(IHttpClientFactory clientFactory) : IApiSender
2320
{
24-
public async Task<RoutingResult> Send(RoutingResult routingResult, MessageData messageData)
25-
{
26-
var proxyName = routingResult.NamedProxy ?? Proxy.RoutedClientWithRetry;
27-
var client = clientFactory.CreateClient(proxyName);
28-
29-
HttpRequestMessage request;
30-
31-
request = routingResult.ConvertRoutedContentToFromJson
32-
? messageData.CreateConvertedJsonRequest(
33-
routingResult.FullRouteLink,
34-
routingResult.RouteHostHeader,
35-
routingResult.MessageSubXPath
36-
)
37-
: messageData.CreateOriginalSoapRequest(routingResult.FullRouteLink, routingResult.RouteHostHeader);
38-
39-
var response = await client.SendAsync(request);
40-
var content =
41-
response.StatusCode == HttpStatusCode.NoContent ? null : await response.Content.ReadAsStringAsync();
42-
43-
return routingResult with
44-
{
45-
RoutingSuccessful = response.IsSuccessStatusCode,
46-
ResponseContent = content,
47-
StatusCode = response.StatusCode,
48-
ResponseDate = response.Headers.Date,
49-
};
50-
}
51-
5221
public async Task<HttpResponseMessage> SendSoapMessageAsync(
5322
string method,
5423
string destination,

BtmsGateway/Services/Routing/DecisionSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ await GetResponseContentAsync(cdsResponse, cancellationToken)
103103
return routingResult with
104104
{
105105
RouteFound = true,
106-
RouteLinkType = _btmsToCdsDestination.LinkType,
106+
// RouteLinkType = _btmsToCdsDestination.LinkType,
107107
RoutingSuccessful = true,
108108
FullRouteLink = destination,
109109
StatusCode = cdsResponse.StatusCode,

BtmsGateway/Services/Routing/ErrorNotificationSender.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ await GetResponseContentAsync(cdsResponse, cancellationToken)
9191
return routingResult with
9292
{
9393
RouteFound = true,
94-
RouteLinkType = _btmsToCdsDestination.LinkType,
9594
RoutingSuccessful = true,
9695
FullRouteLink = destination,
9796
StatusCode = cdsResponse.StatusCode,

BtmsGateway/Services/Routing/MessageRouter.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,19 @@ public interface IMessageRouter
1010
Task<RoutingResult> Route(MessageData messageData, IMetrics metrics);
1111
}
1212

13-
public class MessageRouter(
14-
IMessageRoutes messageRoutes,
15-
IApiSender apiSender,
16-
IQueueSender queueSender,
17-
ILogger<MessageRouter> logger
18-
) : IMessageRouter
13+
public class MessageRouter(IMessageRoutes messageRoutes, IQueueSender queueSender, ILogger<MessageRouter> logger)
14+
: IMessageRouter
1915
{
2016
public async Task<RoutingResult> Route(MessageData messageData, IMetrics metrics)
2117
{
2218
var routingResult = GetRoutingResult(messageData);
23-
if (!routingResult.RouteFound || routingResult.RouteLinkType == LinkType.None)
19+
if (!routingResult.RouteFound)
2420
return routingResult;
2521

2622
try
2723
{
2824
metrics.StartRoutedRequest();
29-
30-
routingResult = routingResult.RouteLinkType switch
31-
{
32-
LinkType.Queue => await queueSender.Send(routingResult, messageData, routingResult.FullRouteLink),
33-
LinkType.Url => await apiSender.Send(routingResult, messageData),
34-
_ => routingResult,
35-
};
36-
37-
return routingResult;
25+
return await queueSender.Send(routingResult, messageData, routingResult.FullRouteLink);
3826
}
3927
catch (Exception ex)
4028
{

BtmsGateway/Services/Routing/MessageRoutes.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ public MessageRoutes(RoutingConfig routingConfig, ILogger<MessageRoutes> logger)
2121
_logger = logger;
2222
try
2323
{
24-
if (
25-
routingConfig.NamedLinks.Any(x =>
26-
x.Value.LinkType == LinkType.Url && !Uri.TryCreate(x.Value.Link, UriKind.Absolute, out _)
27-
)
28-
)
29-
throw new InvalidDataException("Invalid URL(s) in config");
30-
31-
if (routingConfig.NamedLinks.Any(x => !Enum.IsDefined(x.Value.LinkType)))
32-
throw new InvalidDataException("Invalid Link Type in config");
3324
_routes = routingConfig.AllRoutes;
3425
}
3526
catch (Exception ex)
@@ -66,19 +57,13 @@ public RoutingResult GetRoute(string routePath, SoapContent soapContent, string?
6657
RouteName = route.Name,
6758
MessageSubXPath = route.MessageSubXPath,
6859
Legend = route.Legend,
69-
RouteLinkType = route.BtmsLinkType,
70-
FullRouteLink = SelectLink(route.BtmsLinkType, route.BtmsLink, routePath),
60+
FullRouteLink = route.BtmsLink,
7161
RouteHostHeader = route.BtmsHostHeader,
7262
ConvertRoutedContentToFromJson = true,
7363
UrlPath = routePath,
74-
StatusCode = StatusCode(),
64+
StatusCode = HttpStatusCode.Accepted,
7565
NamedProxy = route.NamedProxy,
7666
};
77-
78-
HttpStatusCode StatusCode()
79-
{
80-
return route.BtmsLinkType == LinkType.None ? HttpStatusCode.Accepted : default;
81-
}
8267
}
8368
catch (Exception ex)
8469
{
@@ -100,14 +85,4 @@ public bool IsCdsRoute(string routePath)
10085
x.IsCds && x.RoutePath.Equals(routePath.Trim('/'), StringComparison.InvariantCultureIgnoreCase)
10186
);
10287
}
103-
104-
[SuppressMessage(
105-
"SonarLint",
106-
"S3358",
107-
Justification = "The second nested ternary in each case (lines 55, 56, 68, 69) is within a string interpolation so is very clearly independent of the first"
108-
)]
109-
private static string? SelectLink(LinkType linkType, string? link, string routePath)
110-
{
111-
return linkType == LinkType.None ? null : $"{link}{(linkType == LinkType.Url ? routePath : null)}";
112-
}
11388
}

BtmsGateway/Services/Routing/RoutingConfig.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ private RoutedLink[] GetAllRoutes()
1818
{
1919
Name = nr.Key,
2020
BtmsLink = nl.Value.Link.TrimEnd('/'),
21-
BtmsLinkType = nl.Value.LinkType,
2221
BtmsHostHeader = nl.Value.HostHeader,
2322
RoutePath = nr.Value.RoutePath.Trim('/'),
2423
MessageSubXPath = nr.Value.MessageSubXPath,
@@ -48,35 +47,25 @@ public record NamedRoute
4847
public record NamedLink
4948
{
5049
public required string Link { get; init; }
51-
public required LinkType LinkType { get; init; }
5250
public string? HostHeader { get; init; }
5351
}
5452

5553
public record Destination
5654
{
57-
public required LinkType LinkType { get; init; }
5855
public required string Link { get; init; }
5956
public required string RoutePath { get; init; }
6057
public required string ContentType { get; init; }
6158
public string? HostHeader { get; init; }
6259
public string? Method { get; init; }
6360
}
6461

65-
public enum LinkType
66-
{
67-
None,
68-
Url,
69-
Queue,
70-
}
71-
7262
public record RoutedLink
7363
{
7464
public required string Name { get; init; }
7565
public required string Legend { get; init; }
7666
public required string RoutePath { get; init; }
7767
public required string MessageSubXPath { get; init; }
7868
public string? BtmsLink { get; init; }
79-
public required LinkType BtmsLinkType { get; init; }
8069
public string? BtmsHostHeader { get; init; }
8170
public required bool IsCds { get; init; }
8271
public string? NamedProxy { get; init; }

BtmsGateway/Services/Routing/RoutingResult.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public record RoutingResult
1111
public string? Legend { get; init; }
1212
public bool RouteFound { get; init; }
1313
public bool RoutingSuccessful { get; init; }
14-
public LinkType RouteLinkType { get; init; }
1514
public string? FullRouteLink { get; init; }
1615
public string? RouteHostHeader { get; init; }
1716
public bool ConvertRoutedContentToFromJson { get; init; }

BtmsGateway/appsettings.Development.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
"Stub": {
3838
"Link": "http://localhost:9090/stub/"
3939
},
40-
"CdsAlvs": {
41-
"Link": "http://localhost:9090/alvs/"
42-
},
4340
"InboundCustomsDeclarationReceivedTopic": {
4441
"Link": "arn:aws:sns:eu-west-2:000000000000:trade_imports_inbound_customs_declarations.fifo"
4542
}

0 commit comments

Comments
 (0)